|
-
Feb 16th, 2007, 01:26 AM
#1
Thread Starter
Junior Member
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
-
Feb 16th, 2007, 02:11 AM
#2
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
Last edited by zynder; Feb 16th, 2007 at 02:16 AM.
-
Feb 16th, 2007, 03:18 AM
#3
New Member
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
-
Feb 16th, 2007, 10:48 AM
#4
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.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|