dynamic arrays

morecrabs

Member
Licensed User
Longtime User
I don't remember if this was possible or not in visual basic, but after a forums and google search I didn't find an answer here or there so ill just ask the experts

Is it possible to delcare arrays with variables like this? I tried it but it failed?

Private sub Simpsons()
Dim Homer, Marge as int : 'values to be decided when needed
Homer = mylist.size 'or any other size on fly
Marge = sameAsAbove 'size on demand
Dim bart(bart,Lisa) as string

End sub

Is this possible or is this a fantasy situation? And not possible?
if this is possible how do I do it correctly?

Accidental double post sorry
 
Last edited:

morecrabs

Member
Licensed User
Longtime User
Found an article on tech republic about this and in vb this was the supposed syntax

Dim MyArray() As Integer

Before using the array, you must set its size using the ReDim statement:

ReDimMyArray(100)

Now you can use the dynamic array just like any other array. When you need to change its size, use ReDim again. For instance:

ReDimMyArray(250) By default, changing the size of a dynamic array erases all the data in the array. If you want to preserve the data, include the Preserve keyword:

ReDim Preserve MyArray(250)
This will preserve data in the original elements of the array

Gain data storage flexibility in VB6 with dynamic arrays | TechRepublic

Does basic4android support a similar feature?
 
Upvote 0
Top