sub createRS(tmpRS)
eval("set " & tmpRS & " = server.createobject('adodb.recordset')")
end sub
Is this even possible?
Thanks
Brian
Ughhh! Eval/Execute is evil!!
http://blogs.msdn.com/ericlippert/archive/2003/11/01/53329.aspx
You're not planning on storing these objects in Application or Session are
you?
http://www.aspfaq.com/2053
> end sub
>
> Is this even possible?
>
You best course depends on what your purpose is, but for most cases, just
use a dictionary object to maintain a collection of named objects.
dim dictRS
function getNamedRS(tmpRS)
dim rs
if not isobject(dictRS) then
set dictRS=CreateObject("Scripting.Dictionary")
set rs = createobject(adodb.recordset")
dictRS.Add tmpRS, rs
else
if dictRS.exists(tmpRS) then
set rs=dictRS.Item(tmpRS)
else
set rs = createobject(adodb.recordset")
dictRS.Add tmpRS, rs
end if
end if
set getNamedRS = rs
end function
However, don't think about storing any of these objects in Application or
Session.
--
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"
Why not just pass in your named object reference, and use that? By default
vars passed into a sub or function are ByRef, so it should work fine.
eg.
sub createRS(tmpRS)
set tmpRS = server.createobject("adodb.recordset")
end sub
dim oMyRS1 as object, oMyRS2 as object
createRS oMyRS1
createRS oMyRS2
you should have two recordset objects, one called oMyRS1, the other oMyRS2
or use a function instead:
function createRS()
set createRS = server.createobject("adodb.recordset")
end function
set oMyRS1 = createRS()
set oMyRS2 = createRS()
Bob's dictionary suggestion is handy for maintaining a dynamic number of
objects where you don't know, and so can't represent easily in code, the
number of objects you'll be using.
Dan