473,386 Members | 1,795 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,386 software developers and data experts.

Declare variables in own subroutine

Using ASP.net 1.1 and VB

Is it possible to declare variables in their own subroutine?

I had my DIM statements within a sub that worked just fine.
I wanted to be able to use them in another sub, so I isolated them in their
own subroutine.
But when I call that subroutine within another sub and then try to use those
variables, it does not remember that they have been declared. I get the
message, "Name is not declared."

When I have those same variables declared in the exact same way WITHIN the
second sub it works fine.

Sep 14 '07 #1
5 2160
"dancer" <da****@microsoft.comwrote in message
news:e7**************@TK2MSFTNGP02.phx.gbl...
Using ASP.net 1.1 and VB

Is it possible to declare variables in their own subroutine?

I had my DIM statements within a sub that worked just fine.
I wanted to be able to use them in another sub, so I isolated them in
their own subroutine.
But when I call that subroutine within another sub and then try to use
those variables, it does not remember that they have been declared. I get
the message, "Name is not declared."

When I have those same variables declared in the exact same way WITHIN the
second sub it works fine.

If you want a variable to be accessible from multiple routines, you'll
either have to declare the variable at a higher level, or do something like
passing it ByRef. If you can provide a trivial example of what you're doing
and trying to accomplish, even generically, it will probably be a lot easier
to get you from point A to point B.
Sep 14 '07 #2
dancer wrote:
Using ASP.net 1.1 and VB

Is it possible to declare variables in their own subroutine?

I had my DIM statements within a sub that worked just fine.
I wanted to be able to use them in another sub, so I isolated them in their
own subroutine.
But when I call that subroutine within another sub and then try to use those
variables, it does not remember that they have been declared. I get the
message, "Name is not declared."

When I have those same variables declared in the exact same way WITHIN the
second sub it works fine.
When you declare variables inside a method, they are local to the
method. The memory for the variable is allocated on the stack when the
method is called, and the stack pointer is restored when the method
ends, so the variables doesn't exist in any way outside the method.

--
Göran Andersson
_____
http://www.guffa.com
Sep 14 '07 #3
Should I declare the variables again in each subroutine I want to use them
in?
There are 59 variables.

Thanks
"Göran Andersson" <gu***@guffa.comwrote in message
news:Oe**************@TK2MSFTNGP06.phx.gbl...
dancer wrote:
>Using ASP.net 1.1 and VB

Is it possible to declare variables in their own subroutine?

I had my DIM statements within a sub that worked just fine.
I wanted to be able to use them in another sub, so I isolated them in
their own subroutine.
But when I call that subroutine within another sub and then try to use
those variables, it does not remember that they have been declared. I
get the message, "Name is not declared."

When I have those same variables declared in the exact same way WITHIN
the second sub it works fine.

When you declare variables inside a method, they are local to the method.
The memory for the variable is allocated on the stack when the method is
called, and the stack pointer is restored when the method ends, so the
variables doesn't exist in any way outside the method.

--
Göran Andersson
_____
http://www.guffa.com

Sep 14 '07 #4
dancer wrote:
Should I declare the variables again in each subroutine I want to use them
in?
There are 59 variables.

Thanks
That depends on what you want to do.

If you declare two variables with the same name in separate methods,
they are separate variables and have nothing to do with each other. If
you want to use the variables to share data between methods, you have to
declare them as members in a class.

--
Göran Andersson
_____
http://www.guffa.com
Sep 14 '07 #5
How do I "declare them as members in a class"?
I tried declaring them outside my subroutines, thinking they would be
global. But the subroutine still did not recognize them.

"Göran Andersson" <gu***@guffa.comwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
dancer wrote:
>Should I declare the variables again in each subroutine I want to use
them in?
There are 59 variables.

Thanks

That depends on what you want to do.

If you declare two variables with the same name in separate methods, they
are separate variables and have nothing to do with each other. If you want
to use the variables to share data between methods, you have to declare
them as members in a class.

--
Göran Andersson
_____
http://www.guffa.com

Sep 15 '07 #6

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

Similar topics

3
by: Greg Lindstrom | last post by:
Hello- I am running python 2.3. on an HP-9000 box running Unix and have a POSIX script that sets up my production environment. I would like to run the script from inside a python routine and...
1
by: Joe | last post by:
I am trying to write a Perlscript to be used with some HTML pages. Here is how it works: 1.. The first HTML page has a form which requests for user input. Then it passes the QUERY_STRING...
3
by: t-ball | last post by:
I am new to the world of ASP, and at the same time VBscript (also a firt time poster). I am currently creating a multiple page form where the information on the first page needs to be validated....
6
by: David T. Ashley | last post by:
Hi, In my project, I typically declare and define variables in the .H file, i.e. DECMOD_MAIN UINT8 can_message_201_status_global #ifdef MODULE_MAIN = HAS_NEVER_BEEN_RECEIVED #endif ;
6
by: rick | last post by:
Noob problem. I prefer to keep all my scripts in an external '.js' file. I am currently loading the external '.js' file from the header. Problem is I would like to declare a global variable in the...
8
by: Johm | last post by:
In my codes i am often referring to one and the same controls.Is it possible to declare these controls only once and then insert them in all my functions and subs? For example, i am often...
15
by: CR | last post by:
I've noticed that the trend these days is to declare variables in the middle of code instead of at the top. What is the advantage of this? It seems like it makes it hard to reuse variables. Here...
2
by: singlal | last post by:
Hi, my question was not getting any attention because it moved to 2nd page; so posting it again. Sorry for any inconvenience but I need to get it resolved fast. Need your help! ...
1
by: ares.lagae | last post by:
- I have a typelist and I want to declare a member variable for each of the types. How can I do that? E.g. I have the typelist "typedef boost::mpl::vector<int, float> types;" and I want to declare...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.