Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 17th, 2007, 09:19 PM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default generate variable names dinamycally

Hi, I can't figure out how to do this so please I need advice.

Let's say that I have for next loop

like
for i = 1 to N
which N is dynamically generated so i dont know the exact value

now I need to create vars that goes from 1 to N in order to send them in an url

Example:
I need to generate
var1
var2 ..... varN
of course each one will have a value and that...

It cant be in an array since I'm sending those vars in an url.

TIA
 
Old May 17th, 2007, 09:28 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You can't do this. You cant do, for example:

for i=0 to 5
 Dim DynamicVariablei
next

In this case, this will create a variable named DynamicVariablei and not DynamicVariable0, DynamicVariable1, etc.

Variable values are not evaluated in a varible declartion, and this makes sense.

Why can't you use an array?

for i=0 to ubound(myArray)
 Response.redirect "www.mydoamin.com/page.asp?var1=" + myArray(i)
next

That would work just fine.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 17th, 2007, 09:50 PM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i understand what you say.
What I need to do is to get 5 questions (id and string) and 2-4 answer per question (id and string) and send them into a Flash in an url
Is there anther way to state that?

Another question how do I use the DynamicVariablei you created to recall data from it?

TIA

 
Old May 18th, 2007, 06:42 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

In this instance you are probably going to want to use an array, as I demonstrated in my second example above, so just build your query string off of the values in your array.

You would use DynamicVariablei like any other variable you declare.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 21st, 2007, 09:20 AM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi gcorcuera
I think u can generate variable names using a perl-like notation like below:
for ($i to N)
${"var".$i};

This will generate var1, var2 ..... varN, which u can assign values to.

Hope this helps :)
 
Old May 21st, 2007, 09:21 AM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi gcorcuera
I think u can generate variable names using a perl-like notation like below:
for ($i to N)
${"var".$i};

This will generate var1, var2 ..... varN, which u can assign values to.

Hope this helps :)



 
Old May 21st, 2007, 09:26 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

In ASP you can't do this.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 21st, 2007, 09:53 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can use Execute() in ASP to generate variables:
Code:
For i = 1 To 5 
   Execute "var" & i & " = " & i
   Execute "Response.Write var" & i & " & ""<br>""" 
Next





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASSIGNING A JAVA SCRIPT VARIABLE TO A XSL VARIABLE SOMANATHAN10 XSLT 1 February 21st, 2007 04:26 AM
dynamic variable/object names TheBFJ Excel VBA 2 November 13th, 2006 07:11 AM
Object variable or With block variable not set tparrish VB Databases Basics 1 May 25th, 2005 10:25 AM
Problem with variable names shenku Javascript 2 May 6th, 2005 03:46 PM
Generate userform' s variables names joewidmer VB Databases Basics 0 September 17th, 2004 03:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.