Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Variable Names?

Status
Not open for further replies.

spacehawk

Programmer
May 17, 2000
30
US
Is is possible to have a dimensioned variable name like Var(1), Var(2), ... so that you can go through a loop<br>&lt;%<br>For I= 1 to 5<br><br>Response.Write Var(I)<br><br>Next<br>%&gt;<br><br>This format is not working.
 
well i couldnt get u clearly..but if its just for printing values of i then u can write<br><br>&lt;%<br>For I= 1 to 5%&gt;<br><br>&lt;%=I%&gt;<br><br>&lt;%Next<br>%&gt;<br><br><br>
 
I don't want to print the numbers.&nbsp;&nbsp;Let's say Var(1)=&quot;James&quot;, Var(2)=&quot;Mike&quot;, Var(3)=&quot;Bob&quot;, Var(4)=&quot;Billy&quot;, and Var(5)=&quot;Fred&quot;.<br><br>I want to print the values of Var(1) through Var(5). <br><br>&lt;%<br>For count= 1 to 5<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write Var(count)<br>Next<br>%&gt;<br><br>This does not work because it does not return the value of count for each variable.<br>&nbsp;I don't think it can be done&nbsp;&nbsp;with a loop,&nbsp;&nbsp;but if it could, it would save me a lot of time and make the program much more flexible.
 
Dear hawk,<br><br>Are you referring to an 'Array' ?<br><br>-pete
 
Just define the array before you try to use it.&nbsp;&nbsp;For example, if you expect to have 5 values, at the top of the routine or page,<br><br>Dim var(4)<br><br>arrays are zero-based. <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
Thanks,<br><br>I tried this and it still didn't work for my situation.&nbsp;&nbsp;I have the array variable in a request.form as in request.form(var(i)).<br><br>I can <br><br>response.write(i)<br><br>with i=1 and the output is 1 but when I <br><br>response.write(request.form(var(i))) <br><br>it will not return the value of the input.&nbsp;&nbsp;However I can hard code the numbers and <br><br>response.write(request.form(var(1))) <br><br>does return the value of the input.<br><br>Sorry for all the trouble.&nbsp;&nbsp;I am still learning what it can and cannot do.
 
um, I would think just doing<br><br>Response.Write Var(j)<br><br>or whatever the loop value is. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
Try this..<br><br><br>&lt;%For Each x In Request.Form %&gt;<br><br>&lt;%=x%&gt; and &lt;%request.form(x)%&gt;<br><br>&lt;%Next&nbsp;&nbsp;%&gt;<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top