473,837 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("varNa me')
second=rs("varV alue")
Execute(first & "=" & second) ?????????
rs.movenext
Loop

Thanks a lot for help
Michael

Dec 17 '06 #1
6 1741
Michael wrote on 17 dec 2006 in microsoft.publi c.inetserver.as p.general:
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("varNa me')
second=rs("varV alue")
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)
Dec 17 '06 #2
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("varNa me')
second=rs("varV alue")
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,varvalu e 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=createobje ct("scripting.d ictionary")
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"
Dec 17 '06 #3
--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("varN ame")
vsecond=rs("var Value")
myString = vfirst & "=" & vsecond
Execute(myStrin g ) '?????????
response.write ( "vfirst = " & vfirst & "<br>" & vbcrlf)
rs.movenext
Loop
"Michael" <mi************ **@intergraph.c omwrote in message news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
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("varNa me')
second=rs("varV alue")
Execute(first & "=" & second) ?????????
rs.movenext
Loop

Thanks a lot for help
Michael

Dec 17 '06 #4
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]" <re******@NOyah oo.SPAMcomwrote in message
news:ef******** ******@TK2MSFTN GP02.phx.gbl...
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("varNa me')
second=rs("varV alue")
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,varvalu e 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=createobje ct("scripting.d ictionary")
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"

Dec 18 '06 #5
OK, start with the same framework, but instead of the Dictionary object, use
an XML Document:
dim ar, xmldoc, root, node
sql="select varname,varvalu e 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=createob ject("msxml2.Fr eeThreadedDomDo cument")
set root=xmldoc.cre ateElement("roo t")
set xmldoc.document Element=root
for i = 0 to ubound(ar,2)
set node=xmldoc.cre ateElement(ar(0 ,i))
node.text= ar(1,i)
root.appendChil d node
Set Session("variab les")=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.docu mentElement
for each node in root.childNodes
response.write node.nodeName & ": """
response.write node.text & """<BR>"
next

Michael wrote:
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]" <re******@NOyah oo.SPAMcomwrote in message
news:ef******** ******@TK2MSFTN GP02.phx.gbl...
>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("varNa me')
second=rs("varV alue")
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,varvalu e 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=createobje ct("scripting.d ictionary")
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"
Dec 18 '06 #6
Thank you very much Bob. It works perfect.!!!!!!! !!
Michael

"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcomwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
OK, start with the same framework, but instead of the Dictionary object,
use an XML Document:
dim ar, xmldoc, root, node
sql="select varname,varvalu e 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=createob ject("msxml2.Fr eeThreadedDomDo cument")
set root=xmldoc.cre ateElement("roo t")
set xmldoc.document Element=root
for i = 0 to ubound(ar,2)
set node=xmldoc.cre ateElement(ar(0 ,i))
node.text= ar(1,i)
root.appendChil d node
Set Session("variab les")=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.docu mentElement
for each node in root.childNodes
response.write node.nodeName & ": """
response.write node.text & """<BR>"
next

Michael wrote:
>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]" <re******@NOyah oo.SPAMcomwrote in message
news:ef******* *******@TK2MSFT NGP02.phx.gbl.. .
>>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("varNa me')
second=rs("varV alue")
Execute(first & "=" & second) ?????????
rs.movenex t
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,varvalu e from table where ... "
set rs=conn.execute (sql,,1)
if not rs.eof then ar=rs.Getrows
rs.close:se t rs=nothing
conn.close: set conn=nothing

if isArray(ar) then
set dict=createobje ct("scripting.d ictionary")
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"

Dec 18 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1469
by: vegetax | last post by:
I i need a decorator that adds a local variable in the function it decorates, probably related with nested scopes, for example: def dec(func): def wrapper(obj = None): if not obj : obj = Obj() <bind obj to func> return func() return wrapper()
6
19069
by: rick | last post by:
Noob problem. I prefer to keep all my scripts in an external '.js' file. I am currently loading the external '.js' file from the header. Problem is I would like to declare a global variable in the external file, but I keep getting an error about the object does not exist. Can someone tell me where or how to declare a global variable in an external file that is available after the page is loaded.
2
1472
by: Daniel | last post by:
Hello!!! I'm creating controls dinamically in ASP.NET using VB. The problem is that i don't know how to catch the event of each button that i've create (the buttons are created dinamically). Any ideas?? Thanks!!!
2
12941
by: Marco | last post by:
How I can create TextBox dinamically. I have to create 10 textbox dinamically which name will be txtBox_01, txtBox_02, etc... Thanks.
2
1442
by: Fabio Cavassini | last post by:
I have this code that load HTML tags (no including <html> or <body>) into a DIV dinamically... after correctly retrieving the HTML, I assign it to my DIV Container document.getElementById(containerid).innerHTML=page_request.responseText now from main page....I need to get a reference to an Object (a textbox) contained in the dinamically loaded HTML
4
1341
by: Cesar Ronchese | last post by:
Hello. I have a WebForm that contains a Panel object. This panel, at design time is empty. When running, I need to create dinamically a Label and a WebControl (built from the same project). I can create the label and the webcontrol dinamically with no errors, but only the Label appear in the panel when the page is shown in the client browser.
32
2684
by: Mateo | last post by:
I have char *array and it is dinamically alocated.... When I pass it to other function, I need to determine size of this array.... Problem: sizeof operator does not work with dinamically alocated arrays!?!?! How can I determine size of dinamically alocated array.... ? Please advice... Thx!
3
2684
by: valerio | last post by:
Hello all I would like to dinamically allocate an array of array of structures. To explain this: struct file{ char* fileName,int inode) myfiles; struct file{ char* fileName,int inode) mydirs; but I would like to do it dinamically with linked list. I am able to do it for myfiles, but not with mydirs. Pseudo-code is ok.
1
2791
by: ares.lagae | last post by:
- I have a typelist and I want to declare a member variable for each of the types. How can I do that? E.g. I have the typelist "typedef boost::mpl::vector<int, float> types;" and I want to declare member variables with type "int" and "float". - I have a typelist and I want to declare a variable based on each of the types types. How can I do that? E.g. I have the typelist "typedef boost::mpl::vector<int, float> types;" and I want to...
0
9827
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10560
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10263
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9390
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5838
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4034
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3120
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.