Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Help: Dynamic variables syntax

Reply
Thread Tools

Help: Dynamic variables syntax

 
 
Mr. Smith
Guest
Posts: n/a
 
      01-26-2006
Hi.
What's the correct syntax here:
(given the recordset myRS with x records

do until myRS.EOF
txtvar & myRS("serial_number") = myRS("serial_name")
myRS.movenext
loop

..asp will not build the dynamic variables
txtvar1 = "Some name"
txtvar2 = "Any name"
txtvar3 = "Your name"
.....
Based on the serial_number in the current recordset

How can I builde the dynamic variables, and give them a value from my
recordset?

Hope some of you understand, and can help me out....

Regards
Mr. Smith


 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      01-26-2006
Mr. Smith wrote on 26 jan 2006 in microsoft.public.inetserver.asp.general:

> What's the correct syntax here:
> (given the recordset myRS with x records
>
> do until myRS.EOF
> txtvar & myRS("serial_number") = myRS("serial_name")
> myRS.movenext
> loop
>
> .asp will not build the dynamic variables
> txtvar1 = "Some name"
> txtvar2 = "Any name"
> txtvar3 = "Your name"
> ....
> Based on the serial_number in the current recordset
>
> How can I builde the dynamic variables, and give them a value from my
> recordset?
>
> Hope some of you understand, and can help me out....
>


Use an array:

dim txtvar(100)

txtvar(+myRS("serial_number")) = ...

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      01-26-2006
Mr. Smith wrote:
> Hi.
> What's the correct syntax here:
> (given the recordset myRS with x records
>
> do until myRS.EOF
> txtvar & myRS("serial_number") = myRS("serial_name")
> myRS.movenext
> loop
>
> .asp will not build the dynamic variables
> txtvar1 = "Some name"
> txtvar2 = "Any name"
> txtvar3 = "Your name"


I'm assuming the serial numbers do not have to start at 1, or be
consecutive? If so, that means an array will not suit your purposes.
Instead, use a Dictionary object.

Firstly, use GetRows
(http://msdn.microsoft.com/library/en...mthgetrows.asp) to
move your entire recordset into an array. It is more efficient to loop
through an array than it is to loop through a recordset
(http://www.aspfaq.com/show.asp?id=2467). Optionally, you can even control
which fields get included in the array, like this

dim ar
'open your recordset, then
if not myRS.EOF then ar=myRS.GetRows(,,array("serial_name")

You can now immediately close and destroy your recordset and connection,
freeing up those resources and minimizing the time that you are connected to
the database, which is a good thing:

myRS.Close: Set myRS=nothing
myConn.Close: Set myConn=Nothing

Then check to see if ar is an array. If it is, create the Dictionary object:
If not, report that no records were returned.

dim dict
dim i
if not isarray(ar) then
response.write "no records"
else
set dict=createobject("scripting.dictionary")

Then loop through the array:

for i=0 to ubound(ar,2)
dict.add ar(0,i), ar(1,i)
next

Now, instead of saying

response.write "txtvar2 contains " & txtvar2

you can say

response.write "dict(""2"") contains " & dict("2")

end if

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
paul@bullschmidt.com
Guest
Posts: n/a
 
      01-29-2006
You may want to have a look at this:

Using the Eval and Execute Functions
http://www.4guysfromrolla.com/webtech/030300-1.shtml

Best regards,
-Paul
www.Bullschmidt.com - Freelance Web and Database Developer
www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips

 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      01-30-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> You may want to have a look at this:
>
> Using the Eval and Execute Functions
> http://www.4guysfromrolla.com/webtech/030300-1.shtml


And you may want to look at these to see why you shouldn't take that advice:
http://blogs.msdn.com/ericlippert/ar.../01/53329.aspx
http://blogs.msdn.com/ericlippert/ar.../04/53335.aspx

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Put variables into member variables or function variables? tjumail@gmail.com C++ 9 03-23-2008 04:03 PM
Syntax bug, in 1.8.5? return not (some expr) <-- syntax error vsreturn (not (some expr)) <-- fine Good Night Moon Ruby 9 07-25-2007 04:51 PM
[ANN] SqlStatement 1.0.0 - hide the syntax of SQL behind familiarruby syntax Ken Bloom Ruby 3 10-09-2006 06:46 PM
Syntax highligth with textile: Syntax+RedCloth ? gabriele renzi Ruby 2 12-31-2005 02:44 AM
Dynamic Variables? OR Dynamic Controls =?Utf-8?B?VGVyb3M=?= ASP .Net 1 08-10-2004 01:13 PM



Advertisments