Re: object in a sub [object missing?] by Bob
Bob
Sun Nov 06 07:37:46 CST 2005
Dom wrote:
> I tried it with the dim rs statement and it didn't work, so I removed
> it. I had added it right after the functions and subs (I also tried it
> at the top [same result]), like so:
>
> [functions/subs]
>
> dim rs
> housekeeping
> select case qtype
> case 0
> printStatistics
> case 1
> printLog
> end select
> wrap
This should work. Here is a repro where it works for me:
<%
dim rs
sub InitializeRS
set rs=CreateObject("adodb.recordset")
end sub
sub CreateRS
with rs.Fields
.append "col1",adInteger
.append "col2",adVarChar,20
end with
with rs
.Open
.AddNew array(0,1), array(1,"One")
.AddNew array(0,1), array(2,"Two")
.MoveFirst
end with
end sub
Sub DisplayRS
Response.Write rs.GetString(adClipString,," | ","<BR>")
end sub
InitializeRS
CreateRS
DisplayRS
rs.Close
%>
Joe mentioned a potential drawback with using global variables. A
recommended technique is to use only local variables, using arguments to
pass them between methods. Like this:
<%
function InitializeRS
dim rs
set rs=CreateObject("adodb.recordset")
set InitializeRS=rs
end function
sub CreateRS(byref pRS)
with pRS.Fields
.append "col1",adInteger
.append "col2",adVarChar,20
end with
with pRS
.Open
.AddNew array(0,1), array(1,"One")
.AddNew array(0,1), array(2,"Two")
.MoveFirst
end with
end sub
Sub DisplayRS
dim rs
set rs=InitializeRS
CreateRS rs
Response.Write rs.GetString(adClipString,," | ","<BR>")
end sub
DisplayRS
%>
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"