473,320 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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.

Aug 16 '05 #1
2 1667
"steve" <po*********@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro 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
%>
Aug 16 '05 #2
Thank you for your prompt post. I understand how it works now. Thank
you.

Aug 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: YGeek | last post by:
Is there any difference between declaring a variable at the top of a method versus in the code of the method? Is there a performance impact for either choice? What about if the method will return...
3
by: claus.hirth | last post by:
Does the term 'host variable' cover a variable locally declared in a SQL-PL stored procedure? I am asking this question in the context of the SELECT INTO statement.
1
by: Angelo | last post by:
anyone know of anyway to call a subprocedure 'workbook_open()' embedded in an excel workbook from VB in access? i'm working on some code that was already written for an access db and has data...
2
by: Tracer | last post by:
I have a variable named blnAnswer that is a flag in a subprocedure called ValidateEntries() set to true and tripped to false if something fails. When the variable comes out of the subprocedure and...
2
by: GGerard | last post by:
Hello Is there a way to exit all running procedures with one command? Sometimes a procedure(1) will call another procedure(2) which could call a third procedure(3) and what I would like to...
5
by: Newbie in ChiTown | last post by:
I created a subprocedure that includes a recordset as follows: Private Sub Combo17_Click() 'Declaring object and string variables Dim DB As Database Dim rec As Recordset ...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
0
MMcCarthy
by: MMcCarthy | last post by:
We often get questions on this site that refer to the scope of variables and where and how they are declared. This tutorial is intended to cover the basics of variable scope in VBA for MS Access. For...
1
NeoPa
by: NeoPa | last post by:
Problem Description : In VBA there is an option to enforce declaration of variables in your code. With this set, any reference to a variable that has not been previously declared (Dim; Private;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.