473,503 Members | 12,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

basic ?: sharing variables between functions/subs

This is something I should know, but I don't.

Say I have this:

Function
dim variable1
dim variable2

do stuff with the variables

otherFunction()

End Function

function OtherFunction()
do stuff with the variables
end function

How can I get the second function to see the same variables as the first
one? I could obviously pass each one through the function call itself, but
is there a simpler way? Perhaps declaring the first function variables
public or have the second one inherit them? This is where my lack of OOP
understanding shows ;o)

Nov 18 '05 #1
3 1727
Hi Darrel,

It's basically up to you and what you intend to do with these variables. If
they are only needed for the life time of these functions, then you should
pass them in as parameters to your second function. If they are going to be
accessed and used by other methods or functions that, then you want to
declare them outside of the function, at the class.

Variables that are declared within functions are considered to have local
scope and are disposed as soon as the function returns. In general, it is
best to declare your variables with the narrowest scope possible.

--
HTH

Kyril Magnos

Disclaimer: Thinking may cause permanent thought processes to form and be
used.
"darrel" <no*****@hotmail.com> wrote in message
news:eO**************@TK2MSFTNGP12.phx.gbl...
| This is something I should know, but I don't.
|
| Say I have this:
|
| Function
| dim variable1
| dim variable2
|
| do stuff with the variables
|
| otherFunction()
|
| End Function
|
| function OtherFunction()
| do stuff with the variables
| end function
|
| How can I get the second function to see the same variables as the first
| one? I could obviously pass each one through the function call itself, but
| is there a simpler way? Perhaps declaring the first function variables
| public or have the second one inherit them? This is where my lack of OOP
| understanding shows ;o)
|
|
|
Nov 18 '05 #2
> Variables that are declared within functions are considered to have local
scope and are disposed as soon as the function returns. In general, it is
best to declare your variables with the narrowest scope possible.


Well, here's the specifics.

It's an image upload and resize tool.

The main function gets the initial file and then sets a variety of
variables, namely some different paths to different folders.

Then I call the actual function to resize the image. I'm calling this as a
separate function since I need to call it several times, saving different
images each time.

So, I did some digging and what I finally did was just declare these
variables as public at the top of the codebehind page. This seems to work.
What is the drawback (if any) to this method?

-Darrel
Nov 18 '05 #3
Well, declaring anything as public in your class basically says to the world
"Here I am, you can change or use me anytime you want with no
restrictions.". ;)

If you don't want outside consumers to be able to change your variables,
then I would mark them as private, especially if they are only being used in
this one class.

--
HTH

Kyril Magnos

Disclaimer: Thinking may cause permanent thought processes to form and be
used.
"darrel" <no*****@hotmail.com> wrote in message
news:eu**************@tk2msftngp13.phx.gbl...
|> Variables that are declared within functions are considered to have local
| > scope and are disposed as soon as the function returns. In general, it
is
| > best to declare your variables with the narrowest scope possible.
|
| Well, here's the specifics.
|
| It's an image upload and resize tool.
|
| The main function gets the initial file and then sets a variety of
| variables, namely some different paths to different folders.
|
| Then I call the actual function to resize the image. I'm calling this as a
| separate function since I need to call it several times, saving different
| images each time.
|
| So, I did some digging and what I finally did was just declare these
| variables as public at the top of the codebehind page. This seems to work.
| What is the drawback (if any) to this method?
|
| -Darrel
|
|
Nov 18 '05 #4

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

Similar topics

1
2722
by: Mladen Gogala | last post by:
How can I share variables between two processes? Here is my problem? File test1.php: ------------------------------------------------------------------- <?php session_start(); $var1="This...
2
1654
by: Denis_dh | last post by:
Hi, I have a set of Forms and wish to have a varible used by more than one of them but can't seem to figure where to initialise it or how to acess it if I initialise it in a different form...
2
1817
by: Asha Gill | last post by:
hello all how can i share variables between asp.net pages without using the session or anything that has got to do with the global file. can i use properties for this? 1 page calling the other to...
3
1327
by: Mothish K | last post by:
Hello, I am trying to connect 2 of my asp.net applications using context.items collections to share the variables. but it says Could not load type 'Proj2.SignIn'. I have set the...
1
1583
by: Terry Olsen | last post by:
What is the best practice for sharing variables across modules in the same project? I'm doing a console app with different modules for different functions (file i/o, sql commands, string...
6
1646
by: The Colonel | last post by:
In a .vb class function, can I assign user-specific information (e.g. First Name, Role, etc.) to local variables (as opposed to referring to the session variable multiple times)?
1
1620
by: Terry | last post by:
Hi Language: VBA (Excel) I am wanting to execute different functions/subs dependent on a value picked up in a cell on Excel. For example if Cell A1 has the value "name" then I want to be able...
8
23310
by: vishalsethia | last post by:
I was wondering if I declare a variable as global , can I share the same variable in a different file with the updated value. (ie) A global variable value to be used between different files without...
6
1716
by: awhan.iitk | last post by:
I have a set of variables that I want to share across mulitple c++ files. I was using the extern method so far. Is there any other way to do the same. The variables are not constants and I get the...
0
7098
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
7296
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
7364
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...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.