Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Can a variable declared in one sub procedure be used by another subprocedure?

Reply
Thread Tools

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

 
 
steve
Guest
Posts: n/a
 
      08-16-2005
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.

 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      08-16-2005
"steve" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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
%>


 
Reply With Quote
 
 
 
 
steve
Guest
Posts: n/a
 
      08-16-2005
Thank you for your prompt post. I understand how it works now. Thank
you.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Death To Sub-Sub-Sub-Directories! Lawrence D'Oliveiro Java 92 05-20-2011 06:50 AM
Recognising Sub-Items and sub-sub items using xslt Ben XML 2 09-19-2007 09:35 AM
Fill a javascript var with the content of a variable declared in a vb.net Sub diac ASP .Net 1 10-04-2006 07:13 PM
How can we access a text box in a "sub" that has been created in another "sub" dynamically loga123 ASP .Net 2 05-20-2006 08:47 AM
declared or not declared ? JohnZing ASP .Net 3 02-05-2006 08:38 PM



Advertisments