Array Size Changer
Yuval S.
Tel Aviv,

Dec 27, 2018
6 Posts

Array size changer

Hi all,

I need a suggestion on how to implement this issue:

i need to make a function that always work in the background, contains an array (Public array) and receives long type variables and changes its size according to the input variables on by one:

for example, the array starts like this : Arr[0]
function receives 1st number: 4
so:  Arr[0] = 4
now the functions receives 2nd number: 6
so the array changes it's size (with Redim preserved) so:

Arr[0] = 4
Arr[1] = 6

Any suggestion or a direction on how to build this code will be appreciated,

Thanks !

Jason D.
Irvine, CA

Dec 27, 2018
32 Posts

Re: Array size changer

Hi Yuval,

What you are looking for can be done with the "redim preserve" statement as you mention, but you may want to look into lists.

I have attached an example using ArrayLists to my post.

But in case you want to do it with "redim preserve" anyway, you would create a function that would look something like this:
lSize = sizeof(Arr)/sizeof(Arr[0])
redim preserve Arr[lSize+1]
Arr[lSize] = lNewValue

Regards,
Jason


File Attachment:
Test ArrayList.zip

Solution Available
Paul T.
Maennedorf, Zurich

Dec 27, 2018
54 Posts

Re: Array size changer

Hi Yuval,

I believe you can define a public array of initial dimension 1, and a public boolean flag bFirstNumber=true.
Arr[1]

Then you have the local function:
AppendData(long lValue)
{
  (local) long lSize;
  lSize = VarDimSize(Arr);
  If lSize=1 and bFirstNumber then
    Arr[0]=lValue;
    bFirstNumber=false;
  Else
    Redim Preserve Arr[lSize+1];
    Arr[lSize]=lValue;
}

Let me know if this is what you were asking for or if I got it wrong.

Best regards,
Paul

Yuval S.
Tel Aviv,

Dec 31, 2018
6 Posts

Re: Array size changer

Thanks to you all !

This code solved my problem:

  (local) long lSize;
  lSize = VarDimSize(Arr);
  If lSize=1 and bFirstNumber then
    Arr[0]=lValue;
    bFirstNumber=false;
  Else
    Redim Preserve Arr[lSize+1];
    Arr[lSize]=lValue;
}


Thanks !



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]