Click to See Complete Forum and Search --> : Declaring arrays


David Harrison
11-17-2004, 01:29 PM
Hey there, I'm a bit stuck at the moment and I'd appreciate any help you can give.

I know that I can declare an array like so:
dim blah(10)

However, I need to declare an array a bit like this:
dim blah(someVariable)

Unfortunately I get an error spat out at me, something to the effect of "expected an interger constant". So I tried to do something like this:
i someVariable=10
dim blah(someVariable)

And I get the same error. Can anyone help me out here? Is there an alternative way to declare an array or perhaps add each item into the array as I need to?

russell
11-17-2004, 01:42 PM
dim someVariable
dim blah

someVariable = 10
redim blah(someVariable)

schizo
11-17-2004, 02:02 PM
also...

redim preserve blah(someVariable)

If you want the array to remember all the previous values after rediming.

David Harrison
11-17-2004, 03:44 PM
Ah, thanks guys. That redim seemed to do the trick, I put it to good use on my recent comments (http://www.quiterude.com/recent.asp) page, previously I had to put the number in by hand! :eek:

I'll be able to add a form to the page now and allow the user control over how many comments per page there are.