I just dont get it....please help
why doesnt this code work ??
VB Code:
Private Sub Command2_Click()
Dim aa As Integer
aa = 1
Dim ad(aa) As String
End Sub
iam in a situation where i have to declare an array that has a size based on a variable....so if the variable value is 1 then the array declared will be of size 1 if the variable value is 2 then the array declared will be of size 2 and so on.....how would i go about achieving this task....any help will be greatly appreciated
Re: I just dont get it....please help
No you can't.
On second thought...
VB Code:
Private Sub Command1_Click()
Dim aa As Integer
aa = 1
Dim ad() As String
ReDim ad(aa)
End Sub
Re: I just dont get it....please help
If you want to begin index from 1
you could do as follows
VB Code:
Private Sub Command1_Click()
Dim aa As Integer
aa = 1
Dim ad() As String
ReDim ad(1 to aa)
End Sub
Re: I just dont get it....please help
The reason you can't do it your way is that Dim'ing a fixed-size array requires a constant for the array size (the number has to be known at compile time, so the compiler can allocate enough memory for the array). Since the value of a variable isn't known at compile time, even if it's only set once and never changed, it can't be used to set a fixed-size array.