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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable's value instead of name

Status
Not open for further replies.

JimEkleberry

Programmer
Dec 25, 2001
150
US
How do you use the value of a variable in a statement instead of it's name?

For example, you have a function
Code:
   Sub QueryDB(strRSName, strQuery)
      Set strRSName = Server.CreateObject("ADODB.Recordset")
      strRSName.Open strQuery, objConn, adOpenStatic, adLockReadOnly
   End Sub

but this function will create a recordset actually named strRSName instead of the value that it was passed.

I am sure that this is easy but I cannot find the answer after searching 3 web sites, including Microsoft, and 2 books.

Perhaps I just do not know the proper name to look for.

Thanks for any help that you can provide.
 
Hey Jim,

Use Eval for this.

I think the syntax would be :
dothis = "Sub QueryDB(" & strRSName & ", strQuery)
Set strRSName = Server.CreateObject(""ADODB.Recordset"")"
eval(dothis)
dothis = strRSName & ".Open strQuery, objConn, adOpenStatic, adLockReadOnly"
eval(dothis)
End Sub

the idea is to create the line of text exactly as you want ASP to see it then EVAL(uate) that expression.

There is another way using Execute to do more then one line of code at a time but I don't use it often so I wont try to tell you how to use it.

I hope it helps...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top