to assign value to all of them you can do it like this.
for i = 0 to 11
acct(i) = "Value " & i
next
now acct will contain
value 0
value 1
value 3
value 4
etc
Main Topics
Browse All TopicsI have a need to keep many variables on 1 specific page. I have the code completely written and everything works.
For example, I have 12 variables for the same type of thing (no they aren't months ;) like Act1, Act2, Act3... Act12.
Is there any way to reference the variables more dynamically? I'm using VBScript. I'd like to do something like:
For x = 1 to 12
Act&x = 0
Next
Instead of
Act1 = 0
Act2 = 0
Act3 = 0 ... Act12 = 0
Is there anyway to do that?
I know I can use arrays, but at some point I need to asign them to variables and I'd like to do it in a loop vs individually. I'm pretty sure I could use the Dictionary object as I have used in the past, but I want to try doing without that so the code is a bit more straightforward.
Lastly, is there anyway to put multiple statements on a line using VBScript in ASP?
Thanks!!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The execute function is what you're lookig for here. Here's a code snippet demoing this (this is clinet side for ASP the msgbox won't work):
<script language=vbscript>
dim act3,act4
dim x
x=3
act4=7
execute("act" & x & "=5")
msgbox act3:msgbox act4
</script>
Also note that I've included the syntax for putting multiple statements on a line - use a colon to distinguish each statement
The execute command will still do the job:
<script language=vbscript>
Option explicit
dim x
x=3
execute ("dim act"&x)
execute("act" & x & "=5")
msgbox act3
</script>
or
<script language=vbscript>
Option explicit
execute ("dim act"&cstr(3))
execute("act" & 3 & "=5")
msgbox act3
</script>
with no variables at all created : note the need to explicitly convert to string in the dim statement in the second sample.
First, thanks for all the responses.
I can/will use an array, but I need to eventually assign them to variables as I explained in the initial question.
I'm trying the execute() function, but I get a syntax error. Here's the code snippet...
<%
dim x
for x = 1 to 12
execute("dim PassExp"&cstr(x))
execute("PassExp"&cstr(x)&
next
for x = 1 to 12
response.write "PassExp"&cstr(x)&"="&exec
next
%>
The syntax error is on the 2nd execute stmt where I try to assign a date. Any ideas?
Also, any way to code multiple statements per line using VBScript & ASP?
Thanks.
I think I narrowed it down. I shouldn't use cstr() in the code I posted.
That last error I need to get around has to do with the response.write statement I posted. I need it to put out the value for the variable. In your code, you hard-coded the variable. Is there a way to refer to the variable all on it's own?
Here's the statement that gets an error now:
response.write "PassExp"&x&"="&execute("P
when executed in the loop produces the following error:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'PassExp1'
I guess it doesn't know what to do with just the expression PassExp1.
Any ideas?
Here is the working code not the need to use the eval function when you want to actually write out the var values:
<%
dim x
for x = 1 to 12
execute("dim PassExp" & x)
execute("PassExp" & x & "="&chr(34)&"1/1/01"&chr(3
next
for x = 1 to 12
response.write "PassExp"&x&"="&eval("Pass
next
%>
or to run it multiple lines
<%
dim x
for x = 1 to 12
execute("dim PassExp" & x&":PassExp" & x & "="&chr(34)&"1/1/01"&chr(3
next
for x = 1 to 12
response.write "PassExp"&x&"="&eval("Pass
next
%>
Marine,
I'll use an array internally on the page, but if I want to for example, post a form with variables, I need to set/get them into an array.
Here's an example:
You can have up to 12 different values for something. I create 12 different form fields, each with a unique name like Exp1, Exp2, ... Exp12
Those values are posted from the form and I get read them using Request.Form("Exp1")
Well, like I mentioned in the original question, I can do something like:
Exp(1) = Request.Form("Exp1")
Exp(2) = Request.Form("Exp2") etc
Or now I can do the following in a loop instead of individually coding each:
Exp(x) = evaluate("Request.Form('Ex
Make sense?
Marine, kinda slick... I had to look it up too;
The Execute method allows you to call another ASP page from inside an ASP page. When the called ASP page completes its tasks, you are then returned to the calling ASP page. The overall effect is very similar to a function or subroutine call. Any text or output from the called ASP page will be displayed on the calling ASP page. The Execute method is a more useful alternative to using server-side includes.
In contrast, the Transfer method allows you to transfer from one ASP page to another without returning to the calling ASP page.
There is one mandatory argument.
Path
The Path argument is a string specifying either the absolute or relative path of the ASP page being called. The file name must be included in the path. The entire Path must be enclosed inside a pair of quotes. The Path argument can also include a query string.
Code:
----------CallingAsp.asp--
<HTML>
<BODY>
How now <%Server.Execute("CalledAs
</BODY>
</HTML>
----------CalledAsp.asp---
<%
Response.Write "pink"
%>
Output:
How now pink cow?
Business Accounts
Answer for Membership
by: MarinePosted on 2000-06-17 at 09:29:56ID: 2973771
make an array of them
Dim acct(12)
now you can access them like this
acct(0)
acct(1)
etc.