PDA

Click to See Complete Forum and Search --> : Array question


Aratex
Nov 1st, 1999, 03:59 AM
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

MartinLiss
Nov 1st, 1999, 04:59 AM
No, but you can Redim it if you need to.

------------------
Marty

clint_22
Nov 1st, 1999, 05:00 AM
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.

Aratex
Nov 1st, 1999, 08:54 AM
Hey, thanks guys. :-)


Now what are the odds that I can keep this variable that I'm constantly ReDim-ing Global the whole time?

PhilipG
Nov 1st, 1999, 09:32 AM
Declare it as Static!

Phil

Aratex
Nov 1st, 1999, 10:04 AM
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.

Manish
Nov 1st, 1999, 12:03 PM
hello friends
You can declare an array like this
dim sarray(ubound) as string
u need to declare "ubound" as constant
Thanx Manish

Aratex
Nov 1st, 1999, 12:26 PM
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?

Manish
Nov 1st, 1999, 12:33 PM
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

clint_22
Nov 2nd, 1999, 01:48 AM
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.

clint_22@yahoo.com