Dynamic ASP Local Variables...

@

@sh

I'd like to create a series of variables created dynamically, example such
as this...

For i = 1 to 5
TheVariable & i = "blah"
Next

This would during the first loop create a variable called 'TheVariable1'
with a value of 'blah'. Is this possible as so far I'm getting syntax
errors?

Cheers!
 
R

Ray Costanzo [MVP]

Use an array!
Dim TheVariable[4]
For i = 1 to 5
TheVariable = "blah value #" & i
Next

Response.Write "For example, the third value is " & TheVariable[2]

(Arrays are zero-based in vbscript, so the first element is 0, second is 1,
and so on.)

Ray at work
 
@

@sh

That is so ridiculously obvious I'm blushing....sorry - I'm getting "haven't
developed for a while" syndrome, where functions/commands begin to creep
back into your mind, hehe

Many thanks!


Ray Costanzo said:
Use an array!
Dim TheVariable[4]
For i = 1 to 5
TheVariable = "blah value #" & i
Next

Response.Write "For example, the third value is " & TheVariable[2]

(Arrays are zero-based in vbscript, so the first element is 0, second is
1, and so on.)

Ray at work

@sh said:
I'd like to create a series of variables created dynamically, example
such as this...

For i = 1 to 5
TheVariable & i = "blah"
Next

This would during the first loop create a variable called 'TheVariable1'
with a value of 'blah'. Is this possible as so far I'm getting syntax
errors?

Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top