declaration question

tom2knox
02-12-2004, 06:54 PM
how can i declare an unbounded array???

MikeJ
02-12-2004, 06:58 PM
Dim MyArray() As MyType
---
However, to put data in it, you will need the ReDim keyword (unless you are using a function, which automatically sets the bounds [like Split]). So, to be able to add 2 things to it:

ReDim MyArray(1) As MyType

You can now access MyArray(0) and MyArray(1). But, lets say you want more data. If you ReDim it again, it will clear the values of the other variables. So, you need to use the ReDim Preserve keyword:

ReDim Preserve MyArray(2) As MyType

You now have access to MyArray(0) and MyArray(1), which keeps their old values, and then you have MyArray(2), which you can do whatever you want with as well.

tom2knox
02-12-2004, 07:06 PM
thnx mike j.... it is a big help... but why does the value in the pointer 2 is null here is my code...

Private tstArray() As String
Private Sub Command3_Click()
ReDim Preserve tstArray(1 To 3) As String

For x = 1 To Text1
MsgBox x
Next x
End Sub

Private Sub Command4_Click()
MsgBox tstArray(2)
End Sub

tom2knox
02-12-2004, 07:15 PM
im sorry ive got it solved...

Private tstArray() As String
Private Sub Command3_Click()
ReDim Preserve tstArray(1 To 3) As String

For x = 1 To Text1
tstArray(x) = x ' ive forgot this line... lolz
MsgBox x
Next x
End Sub

Private Sub Command4_Click()
MsgBox tstArray(2)
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum