Can I declare an array with unknown size?
Such as:
Dim strCode() As String
Printable View
Can I declare an array with unknown size?
Such as:
Dim strCode() As String
Er.. Yes..! Then you use the Redim function to change the size of it at run time.
yes, and just to add to Buzby's post, use ReDim Preserve to keep all your existing array elements when you extend your array
i.e.
Code:Dim s() as String 'string array
Dim i%
for i = 1 to 10
ReDim Preserve s(i)
Next i
To add an item to the array you would have to ReDim the array and use "Preserve" to keep the values:
Code:Dim strCode As String
Dim topVar As Integer
Dim i As Integer
Dim YourNum as Integer
For i = 1 To YourNum
topVar = UBound(strCode)+1
ReDim Preserve strCode(topVar) As String
strCode(topVar) = "This is the last item in the array"
Next