Can a variable declared in one sub procedure be used by another subprocedure?

S

steve

I have Option Explicit ON by the way.

I have declared a variable in one subprocedure which is being used by
another subprocedure. But it doesn' seem to work. I am doing something
similar to this (but obviously with much more code):


<%
Option Explicit
Call X
Call Z

Sub X
Dim Y
Y = "Hello"
End Sub

Sub Z
response.write Y
End Sub
%>

Is this not possible and is there anyway (apart from breaking up the
sub procedures) of keeping the code separated and organized in this
fashion.
 
M

McKirahan

steve said:
I have Option Explicit ON by the way.

I have declared a variable in one subprocedure which is being used by
another subprocedure. But it doesn' seem to work. I am doing something
similar to this (but obviously with much more code):


<%
Option Explicit
Call X
Call Z

Sub X
Dim Y
Y = "Hello"
End Sub

Sub Z
response.write Y
End Sub
%>

Is this not possible and is there anyway (apart from breaking up the
sub procedures) of keeping the code separated and organized in this
fashion.

"Sub Z" doesn't know about "Y" unless you declare it globally:

<%
Option Explicit
Dim Y
Call X
Call Z

Sub X
Y = "Hello"
End Sub

Sub Z
response.write Y
End Sub
%>
 

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

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top