Home AMX User Forum NetLinx Studio
Options

SEt_LENGTH_ARRAY not working

Hi,

I have the following and it doesn't seem to be working. I've been debugging it and it seems that the SET_LENGTH_ARRAY doesn't seem to get set

STRUCTURE _Person
{
CHAR FirstName[20]
CHAR LastName[20]
}

NON_VOLATILE CHAR FirstName[20]
NON_VOLATILE CHAR LastName[20]
_Person People

In a button push event I have the following

PUSH:
{
WHILE (x < 5)
{
FirstName = REMOVE_STRING(Name, ' ')
LastName = Name
FirstName = LEFT_STRING(FirstName, LENGTH_ARRAY(Name) - 1)

People[MAX_LENGTH_ARRAY(People)].FirstName = FirstName
People[MAX_LENGTH_ARRAY(People)].LastName = LastName

SET_LENGTH_ARRAY(People, MAX_LENGTH_ARRAY(People) + 1)

x = x + 1
}
}

This loops 5 times, but my People structure at the end only contains 1 name, the last name. I want it to store all names that it receives. Some code regarding where the name is coming from is not included for simplicity sake.

It looks like the SET_LENGTH_ARRAY function doesn't expand the array. Am I doing something wrong here?

Thanks,

Javed

Comments

  • Options
    mpullinmpullin Posts: 949
    javedwahid wrote: »
    This loops 5 times, but my People structure at the end only contains 1 name, the last name. I want it to store all names that it receives. Some code regarding where the name is coming from is not included for simplicity sake.

    It looks like the SET_LENGTH_ARRAY function doesn't expand the array. Am I doing something wrong here?
    Yes. Arrays in NetLinx are not vectors. You can't just declare a 1-cell array and expand it later. The biggest possible size of the array is set at compile time so declare your array to be as big (or bigger) than it will ever need to be. SET_LENGTH_ARRAY just moves the internal flag for that array to determine which the last cell used is.
  • Options
    ok, now it makes sense, thanks for clarifying how the arrays work. I'll figure out a different approach.
Sign In or Register to comment.