I might just be dumb, but is there any way to Dim an array using a variable? IE. Dim Array(1 To UBoud, 1 To 3) As String
Printable View
I might just be dumb, but is there any way to Dim an array using a variable? IE. Dim Array(1 To UBoud, 1 To 3) As String
No, but you can Redim it if you need to.
------------------
Marty
I wrote a program where I wanted a varying number of elements without having to keep updating code. I did something like this:
FileCount = FileCount + 1
ReDim Preserve NumFiles(FileCount)
Then I added my new element:
NumFiles(FileCount) = file$
This may be what you want to do.
Hey, thanks guys. :-)
Now what are the odds that I can keep this variable that I'm constantly ReDim-ing Global the whole time?
Declare it as Static!
Phil
Thanks, Phil. :-)
Sorry for askin' all the dumb questions, I haven't had VB for long and I'm still trying to do most of my coding QB style. Most of it works, though.
hello friends
You can declare an array like this
dim sarray(ubound) as string
u need to declare "ubound" as constant
Thanx Manish
Another question for you guys 'cause I'm dumb... Well, OK. It's the same question again.
The Static thing isn't working. Not the way I want it to. From what I've read now that I looked it up, Static claims that it still only works in one Sub but that it endures repeated calls. I need to be able to repeatedly ReDim the array, but I need it to be legitimately Global so that I can share it with many different Subs. Is Static really right and I'm just not doing it right or is there some other way?
hi
what i understand is u want a constant value and want to redim an array on the basis of the constant value. Am i right?? u can use constant declare it in a form or in a BAS according to yr need and u can use it. as per the scope.
Thanx Manish
Hey, I just read your recent question. I had the Global MyArray() as string in the declaration and set the array to zero before the loop by putting ReDim MyArray(0) before the loop began. Also, you can declare the variable you are resetting the MyArray length to as Global as well. Well, I hope that this will shed more light on your question. Sorry, I should have put this stuff in there too. Let me know if I can be of more help.
[email protected]