
December 17th, 2006, 04:45 PM
| | | Dinamically Declare variable in ASP
Hi. I am trying to declare variables based on DB column.
I have a table with 2 columns:
"varname" and "varvalue".
values for example:
varName: 'varPhone'
varValue: '450-111-2222'
During the looping I'd like to declare on asp page variables that taken from
varname column and assign values taken from varValue column.
i think the Execute method can help me, but failed to do this.
Some code I am going to use is here:
Do while not rs.eof
first=rs("varName')
second=rs("varValue")
Execute(first & "=" & second) ?????????
rs.movenext
Loop
Thanks a lot for help
Michael | 
December 17th, 2006, 05:15 PM
| | | Re: Dinamically Declare variable in ASP
Michael wrote on 17 dec 2006 in microsoft.public.inetserver.asp.general: Quote:
Hi. I am trying to declare variables based on DB column.
I have a table with 2 columns:
"varname" and "varvalue".
>
values for example:
varName: 'varPhone'
varValue: '450-111-2222'
>
During the looping I'd like to declare on asp page variables that
taken from varname column and assign values taken from varValue
column. i think the Execute method can help me, but failed to do this.
>
Some code I am going to use is here:
>
Do while not rs.eof
first=rs("varName')
second=rs("varValue")
Execute(first & "=" & second) ?????????
rs.movenext
Loop
| I think that is a bad idea,
because you will get into trouble over reserved names.
Try ASP-jscript and an enumerated object/array.
var namesObject[]
namesObject[first] = second
No eval-like evil tures necessary.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress) | 
December 17th, 2006, 05:25 PM
| | | Re: Dinamically Declare variable in ASP
Michael wrote: Quote:
Hi. I am trying to declare variables based on DB column.
I have a table with 2 columns:
"varname" and "varvalue".
>
values for example:
varName: 'varPhone'
varValue: '450-111-2222'
>
During the looping I'd like to declare on asp page variables that
taken from varname column and assign values taken from varValue
column. i think the Execute method can help me, but failed to do this.
| Execute is "evil" : http://blogs.msdn.com/ericlippert/ar.../01/53329.aspx. Quote:
>
Some code I am going to use is here:
>
Do while not rs.eof
first=rs("varName')
second=rs("varValue")
Execute(first & "=" & second) ?????????
rs.movenext
Loop
>
Thanks a lot for help
Michael
| Why are you doing this? It's not like you are going to even know the names
of these variables until runtime. What is the point?
Let's assume you have some valid reason for doing this. Are you planning to
store these things in Session or Application?
If so, I would suggest storing it as an xml document (if you need some code
for this, let us know).
If not, I would recommend using a Dictionary object instead of using the
"evil" Execute method For the best efficiency, I would suggest using a
GetRows array, like this:
dim ar, dict
sql="select varname,varvalue from table where ... "
set rs=conn.execute(sql,,1)
if not rs.eof then ar=rs.Getrows
rs.close:set rs=nothing
conn.close: set conn=nothing
if isArray(ar) then
set dict=createobject("scripting.dictionary")
for i = 0 to ubound(ar,2)
dict.add ar(0,i), ar(1,i)
next
else
response.write "no data was retrieved"
end if
--
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" | 
December 17th, 2006, 05:35 PM
| | | Re: Dinamically Declare variable in ASP
--try creating it as a string first,
--you also have a typo in : rs("varName')
Dim myString ,vfirst,vsecond
Do while not rs.eof
vfirst=rs("varName")
vsecond=rs("varValue")
myString = vfirst & "=" & vsecond
Execute(myString ) '?????????
response.write ( "vfirst = " & vfirst & "<br>" & vbcrlf)
rs.movenext
Loop
"Michael" <michael.groysman@intergraph.comwrote in message news:%23NO7ElfIHHA.3424@TK2MSFTNGP02.phx.gbl... Quote:
Hi. I am trying to declare variables based on DB column.
I have a table with 2 columns:
"varname" and "varvalue".
>
values for example:
varName: 'varPhone'
varValue: '450-111-2222'
>
During the looping I'd like to declare on asp page variables that taken from varname column and assign values taken from varValue
column.
i think the Execute method can help me, but failed to do this.
>
Some code I am going to use is here:
>
Do while not rs.eof
first=rs("varName')
second=rs("varValue")
Execute(first & "=" & second) ?????????
rs.movenext
Loop
>
Thanks a lot for help
Michael
>
>
>
| | 
December 18th, 2006, 06:35 AM
| | | Re: Dinamically Declare variable in ASP
Thank you for respond. I'd like to explain Idea of script I need. All
variable i am using on website I'd like to use as constants during web
session. I mean to load all constants(that kept in varName field) at the
beginning of session and after that to use them in all pages while web user
is connected.
The another ideas I think could be generating the asp file(every time after
editing my table) which will "include" file and will be used by "include"
statement. The XML style Code very appreciated. Thanks again
Michael
"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcomwrote in message
news:ef5S79fIHHA.3424@TK2MSFTNGP02.phx.gbl... Quote:
Michael wrote: Quote:
>Hi. I am trying to declare variables based on DB column.
>I have a table with 2 columns:
>"varname" and "varvalue".
>>
>values for example:
>varName: 'varPhone'
>varValue: '450-111-2222'
>>
>During the looping I'd like to declare on asp page variables that
>taken from varname column and assign values taken from varValue
>column. i think the Execute method can help me, but failed to do this.
| >
Execute is "evil" : http://blogs.msdn.com/ericlippert/ar.../01/53329.aspx.
> Quote:
>>
>Some code I am going to use is here:
>>
>Do while not rs.eof
> first=rs("varName')
> second=rs("varValue")
> Execute(first & "=" & second) ?????????
>rs.movenext
>Loop
>>
>Thanks a lot for help
>Michael
| >
Why are you doing this? It's not like you are going to even know the names
of these variables until runtime. What is the point?
>
Let's assume you have some valid reason for doing this. Are you planning
to store these things in Session or Application?
>
If so, I would suggest storing it as an xml document (if you need some
code for this, let us know).
>
If not, I would recommend using a Dictionary object instead of using the
"evil" Execute method For the best efficiency, I would suggest using a
GetRows array, like this:
>
dim ar, dict
sql="select varname,varvalue from table where ... "
set rs=conn.execute(sql,,1)
if not rs.eof then ar=rs.Getrows
rs.close:set rs=nothing
conn.close: set conn=nothing
>
if isArray(ar) then
set dict=createobject("scripting.dictionary")
for i = 0 to ubound(ar,2)
dict.add ar(0,i), ar(1,i)
next
else
response.write "no data was retrieved"
end if
>
>
>
>
>
--
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"
>
| | 
December 18th, 2006, 12:05 PM
| | | Re: Dinamically Declare variable in ASP
OK, start with the same framework, but instead of the Dictionary object, use
an XML Document:
dim ar, xmldoc, root, node
sql="select varname,varvalue from table where ... "
set rs=conn.execute(sql,,1)
if not rs.eof then ar=rs.Getrows
rs.close:set rs=nothing
conn.close: set conn=nothing
if isArray(ar) then
set xmldoc=createobject("msxml2.FreeThreadedDomDocumen t")
set root=xmldoc.createElement("root")
set xmldoc.documentElement=root
for i = 0 to ubound(ar,2)
set node=xmldoc.createElement(ar(0,i))
node.text= ar(1,i)
root.appendChild node
Set Session("variables")=xmldoc
next
else
response.write "no data was retrieved"
end if
Here is an example of processing that document:
dim xmldoc, root, node
set xmldoc=Session("variables")
set rootxmldoc.documentElement
for each node in root.childNodes
response.write node.nodeName & ": """
response.write node.text & """<BR>"
next
Michael wrote: Quote:
Thank you for respond. I'd like to explain Idea of script I need. All
variable i am using on website I'd like to use as constants during web
session. I mean to load all constants(that kept in varName field) at
the beginning of session and after that to use them in all pages
while web user is connected.
>
The another ideas I think could be generating the asp file(every time
after editing my table) which will "include" file and will be used by
"include" statement. The XML style Code very appreciated. Thanks
again Michael
>
>
>
"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcomwrote in message
news:ef5S79fIHHA.3424@TK2MSFTNGP02.phx.gbl... Quote:
>Michael wrote: Quote:
>>Hi. I am trying to declare variables based on DB column.
>>I have a table with 2 columns:
>>"varname" and "varvalue".
>>>
>>values for example:
>>varName: 'varPhone'
>>varValue: '450-111-2222'
>>>
>>During the looping I'd like to declare on asp page variables that
>>taken from varname column and assign values taken from varValue
>>column. i think the Execute method can help me, but failed to do
>>this.
| >>
>Execute is "evil" :
>http://blogs.msdn.com/ericlippert/ar.../01/53329.aspx.
>> Quote:
>>>
>>Some code I am going to use is here:
>>>
>>Do while not rs.eof
>> first=rs("varName')
>> second=rs("varValue")
>> Execute(first & "=" & second) ?????????
>>rs.movenext
>>Loop
>>>
>>Thanks a lot for help
>>Michael
| >>
>Why are you doing this? It's not like you are going to even know the
>names of these variables until runtime. What is the point?
>>
>Let's assume you have some valid reason for doing this. Are you
>planning to store these things in Session or Application?
>>
>If so, I would suggest storing it as an xml document (if you need
>some code for this, let us know).
>>
>If not, I would recommend using a Dictionary object instead of using
>the "evil" Execute method For the best efficiency, I would suggest
>using a GetRows array, like this:
>>
>dim ar, dict
>sql="select varname,varvalue from table where ... "
>set rs=conn.execute(sql,,1)
>if not rs.eof then ar=rs.Getrows
>rs.close:set rs=nothing
>conn.close: set conn=nothing
>>
>if isArray(ar) then
> set dict=createobject("scripting.dictionary")
> for i = 0 to ubound(ar,2)
> dict.add ar(0,i), ar(1,i)
> next
>else
> response.write "no data was retrieved"
>end if
>>
>>
>>
>>
>>
>--
>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"
| | --
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" | 
December 18th, 2006, 03:55 PM
| | | Re: Dinamically Declare variable in ASP
Thank you very much Bob. It works perfect.!!!!!!!!!
Michael
"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcomwrote in message
news:%23Y5sJxpIHHA.1468@TK2MSFTNGP04.phx.gbl... Quote:
OK, start with the same framework, but instead of the Dictionary object,
use an XML Document:
dim ar, xmldoc, root, node
sql="select varname,varvalue from table where ... "
set rs=conn.execute(sql,,1)
if not rs.eof then ar=rs.Getrows
rs.close:set rs=nothing
conn.close: set conn=nothing
>
if isArray(ar) then
set xmldoc=createobject("msxml2.FreeThreadedDomDocumen t")
set root=xmldoc.createElement("root")
set xmldoc.documentElement=root
for i = 0 to ubound(ar,2)
set node=xmldoc.createElement(ar(0,i))
node.text= ar(1,i)
root.appendChild node
Set Session("variables")=xmldoc
next
else
response.write "no data was retrieved"
end if
>
>
>
Here is an example of processing that document:
dim xmldoc, root, node
set xmldoc=Session("variables")
set rootxmldoc.documentElement
for each node in root.childNodes
response.write node.nodeName & ": """
response.write node.text & """<BR>"
next
>
>
>
Michael wrote: Quote:
>Thank you for respond. I'd like to explain Idea of script I need. All
>variable i am using on website I'd like to use as constants during web
>session. I mean to load all constants(that kept in varName field) at
>the beginning of session and after that to use them in all pages
>while web user is connected.
>>
>The another ideas I think could be generating the asp file(every time
>after editing my table) which will "include" file and will be used by
>"include" statement. The XML style Code very appreciated. Thanks
>again Michael
>>
>>
>>
>"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcomwrote in message
>news:ef5S79fIHHA.3424@TK2MSFTNGP02.phx.gbl... Quote:
>>Michael wrote:
>>>Hi. I am trying to declare variables based on DB column.
>>>I have a table with 2 columns:
>>>"varname" and "varvalue".
>>>>
>>>values for example:
>>>varName: 'varPhone'
>>>varValue: '450-111-2222'
>>>>
>>>During the looping I'd like to declare on asp page variables that
>>>taken from varname column and assign values taken from varValue
>>>column. i think the Execute method can help me, but failed to do
>>>this.
>>>
>>Execute is "evil" :
>>http://blogs.msdn.com/ericlippert/ar.../01/53329.aspx.
>>>
>>>>
>>>Some code I am going to use is here:
>>>>
>>>Do while not rs.eof
>>> first=rs("varName')
>>> second=rs("varValue")
>>> Execute(first & "=" & second) ?????????
>>>rs.movenext
>>>Loop
>>>>
>>>Thanks a lot for help
>>>Michael
>>>
>>Why are you doing this? It's not like you are going to even know the
>>names of these variables until runtime. What is the point?
>>>
>>Let's assume you have some valid reason for doing this. Are you
>>planning to store these things in Session or Application?
>>>
>>If so, I would suggest storing it as an xml document (if you need
>>some code for this, let us know).
>>>
>>If not, I would recommend using a Dictionary object instead of using
>>the "evil" Execute method For the best efficiency, I would suggest
>>using a GetRows array, like this:
>>>
>>dim ar, dict
>>sql="select varname,varvalue from table where ... "
>>set rs=conn.execute(sql,,1)
>>if not rs.eof then ar=rs.Getrows
>>rs.close:set rs=nothing
>>conn.close: set conn=nothing
>>>
>>if isArray(ar) then
>> set dict=createobject("scripting.dictionary")
>> for i = 0 to ubound(ar,2)
>> dict.add ar(0,i), ar(1,i)
>> next
>>else
>> response.write "no data was retrieved"
>>end if
>>>
>>>
>>>
>>>
>>>
>>--
>>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"
| | >
--
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"
>
| |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|