ASP: Possible to access variable defined in a Sub?

K

Ken Fine

I have a Sub which defines a variable. I'm wondering if there's anyway I can
get at that variable outside of the context of the Sub -- to pass the
variable's contents to another page, for instance. Here's some truncated
code:

<%
Sub CreateHTMLPage(getURL,postFile)
Dim TearObj
Set TearObj = CreateObject("SOFTWING.ASPTear")
...
Dim strRetrieval
strRetrieval = TearObj.Retrieve(getPage, Request_GET, "", "", "")
....
....
End Sub

%>

At this point, I'd like to be able to get at the contents of variable
strRetrieval and do something with it. Is there any way to make strRetrieval
"public"?
 
B

Bob Lehmann

You could just declare strRetrieval outside of the sub instead of inside.
But it would be better to use a function instead, to return the value.

Function CreateHTMLPage(getURL,postFile)
Dim TearObj
Set TearObj = CreateObject("SOFTWING.ASPTear")
...

CreateHTMLPage = TearObj.Retrieve(getPage, Request_GET, "", "", "")
....
....
End Function

x = CreateHTMLPage val1, val2


Bob Lehmann
 
A

Alan

What Curt said, plus, when I come across something like this I look at the
structure of my application. Perhaps strRetrieval should be defined in the
caller and passed into your sub. You could also change the sub to a function
and return strRetrieval, or pass strRetrieval ByRef.

Alan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,159
Latest member
SweetCalmCBDGummies
Top