Click to See Complete Forum and Search --> : Declaring arrays using variables
DrkMatter
Jan 14th, 2000, 12:53 AM
In one of my programs, I have to declare a variable as follow :
Dim Variable(Param1, Param2)
But everytime I run my program, I get an error warning me that I must use a constant when declaring an array.
Is there any way around this ?
JP
Jan 14th, 2000, 01:02 AM
I think you have to Dim an array using constants or fixed values. To size it using variables use ReDim e.g.
Function x
Dim arrValues(0,0) as integer
Dim x as integer
Dim y as integer
x=10
y=15
ReDim [with preserve] arrValues(x,y)
End
I've not tried this to check it works, but have a go...
JP
MartinLiss
Jan 14th, 2000, 01:03 AM
Do ThisDim Param1 As Integer
Dim Param2 As Integer
Dim Variable() As Integer
Param1 = 1
Param2 = 2
ReDim Variable(Param1, Param2)
------------------
Marty
netSurfer
Jan 14th, 2000, 01:04 AM
have you tried:
dim Variable()
redim Variable(param1, param2)?
netSurfer
Jan 14th, 2000, 01:12 AM
funny, when I posted no one had replied yet. Looking at the times, we probably all responded at the same time. All with basically the same answer. Ok, maybe it's not that funny but it's friday ok. :-)
ravcam
Jan 14th, 2000, 08:18 AM
Ok, a very similar question! I thaught REDIMing was very slow? Would it not be easier to just dim a variable that would be oversized to handle the variable instead of rediming it?
MartinLiss
Jan 14th, 2000, 11:44 AM
Rediming may or may not be slow, but allocating a large array takes up memory. Take your pick.
------------------
Marty
[This message has been edited by MartinLiss (edited 01-15-2000).]
DrkMatter
Jan 16th, 2000, 08:11 AM
Thanks a lot.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.