stefanRusterholz
Programmer
Hi
I'm programming in VB for about 2 weeks now and can't get around following obstacle:
I have got an array (public because it can grow up to a few MB) which is at start erased.
Question 1:
How can I test if that array is still erased or has got redimmed? At the moment I use the workaround of having a secondary (Boolean) Variable 'arrayIsEmpty' which is set to true if the array is erased and fals if not. Is there a better solution for that (something like is_empty(myArray) was great)
Question 2:
Is there a way to 'fill' an array with default values within a given range (e.g. myArray(3) to myArray(209) get filled with "hello"
?
below is a sample of how I'm doing it at the moment:
I hope I made myself clear and someone is able to help me.
Thanks in advance
Stefan
I'm programming in VB for about 2 weeks now and can't get around following obstacle:
I have got an array (public because it can grow up to a few MB) which is at start erased.
Question 1:
How can I test if that array is still erased or has got redimmed? At the moment I use the workaround of having a secondary (Boolean) Variable 'arrayIsEmpty' which is set to true if the array is erased and fals if not. Is there a better solution for that (something like is_empty(myArray) was great)
Question 2:
Is there a way to 'fill' an array with default values within a given range (e.g. myArray(3) to myArray(209) get filled with "hello"
below is a sample of how I'm doing it at the moment:
Code:
' declaring variables
dim arrayIsEmpty as Boolean
dim max as integer, dim lastUBound as integer
dim myArray() as string
' set variables to default
erase myArray
arrayIsEmpty = true
max = 0
lastUBound = -1
' do our stuff
For i = bottom To top
' do some stuff here
' ...
' ...
' stuff done
' smartly increase array size
If arrayIsEmpty Then
arrayIsEmpty = False
ReDim Preserve myArray(0)
End If
If entryAtIndex > UBound(myArray) Then ' NOTE 1: let's suppose entryAtIndex as here a value of 7 in first loop
max = entryAtIndex
ReDim Preserve myArray(max)
If Abs(max - lastUBound) > 1 Then
For j = (lastUBound + 1) To (max - 1)
myArray(j) = "myDefaultValue"
Next j
End If
lastUBound = max
End If
Next i
I hope I made myself clear and someone is able to help me.
Thanks in advance
Stefan