Changing size of array within a struct
Golden M.
Littleton, CO

Sep 15, 2020
1 Post

0  |  0  

Re: Changing size of array within a struct

I have a struct (myStruct) in which there is a field (COMMAND) that I need to be of variable size. ATEasy help states that performing a redim on an array in a struct is not possible. Instead it recommends to use a Variant data type structure field that contains an array and use VarDimSize to change it's dimension. I set the field within the struct to be a variant data type and run the following command:

VarDimSize(myStruct.COMMAND, , newLength)

Nothing changes for the COMMAND field of myStruct. I then tried to change the variant type using VarChangeType:

VarChangeType(myStruct.COMMAND, vtArray)
VarDimSize(myStruct.COMMAND, , newLength)

Again nothing changes for the COMMAND field of my Struct. I also tried this with a local variant variable with the same results. The only way around this that I found was to have two local dummy variables, one a variant and the other an array. I can then change the dimensions of myStruct.COMMAND using the following code:

variant = array
VarDimSize(variant, , newLength)
myStruct.COMMAND = variant

Am I missing something? It seems I should be able to change the size of the variant using the VarDimSize command but am unable to. I appreciate any help.

Solution Available
DrATEasy (Ron Y.)
Mission Viejo, CA

Sep 15, 2020
334 Posts

1  |  0  

Re: Changing size of array within a struct

VarChangeType(myStruct.COMMAND, vtArray) does not allocate an array. You need to assign an array to the variant before. Here is an example:

as: string[1]    ! string array of one element

myStruct.COMMAND=as
myStruct.COMMAND[0]="abc"

VarDimSize(stArray.vrArray,0, 2)
myStruct.COMMAND[1]="def"



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]