473,386 Members | 2,114 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.

Variable Scope, please help

al
Hi,

How can I make a variable declared in a function to be global.That is,
to be seen all over the form code or class I tried to declare the
variable as public, but it didn't work.

MTIA,
Grawsha
Nov 20 '05 #1
3 807
"al" <gr*********@yahoo.com> schrieb

How can I make a variable declared in a function to be global.
In a function is local, never global.
That is,
to be seen all over the form code or class I tried to declare the
variable as public,
That's what I would have suggested now.
but it didn't work.


"Didn't work" is no good description.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Ot

"al" <gr*********@yahoo.com> wrote in message
news:66**************************@posting.google.c om...
Hi,

How can I make a variable declared in a function to be global.That is,
to be seen all over the form code or class I tried to declare the
variable as public, but it didn't work.

MTIA,
Grawsha


Maybe I don't understand your question, but...

Class Foo

Private FooBar ...

Private Sub...
Dim Bar...
Private Sub1...

End Sub

Private Sub X...

End Sub

End Sub

Private Sub2...

End Sub

End Class

FooBar would be visible to all the Subs in the class Foo. The variable Bar
would be visible to the subs inside the sub in which it is declared.

Want it truly global? Declare it outside of your very first construct.

This answer seems too simple, so what did I miss about your question?
Nov 20 '05 #3
"al" <gr*********@yahoo.com> wrote in message
news:66**************************@posting.google.c om...
.. . .
How can I make a variable declared in a function to be global.


Can't be done, for two reasons.

1. Variables declared in a function are local (or possibly Static),
/never/ any more than that. If you want a variable with wider
scope, follow the language rules and declare it elsewhere.
2. "Global" variables can /only/ be declared in Modules, not Classes
(remember Forms /are/ Classes).

To make the variable accessible throughout a Class, make it an
instance variable of the Class, as in

Class abc123
Private siText as String = ""

' This variable can be seen anywhere in /this/ class
' but /not/ outside it
. . .
End Class

HTH,
Phill W.
Nov 20 '05 #4

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

Similar topics

6
by: Brian Jones | last post by:
I'm sure the solution may be obvious, but this problem is driving me mad. The following is my code: class a(object): mastervar = def __init__(self): print 'called a'
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
9
by: garyusenet | last post by:
Hello I'm trying to get to grips with variable scope. I have a very basic programme i'm working on - and am once again being confused by scope of variables. I am just trying to write a new...
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...
5
by: somenath | last post by:
Hi All , I have one question regarding scope and lifetime of variable. #include <stdio.h> int main(int argc, char *argv) { int *intp = NULL; char *sptr = NULL;
5
by: chromis | last post by:
Hi there, I've recently been updating a site to use locking on application level variables, and I am trying to use a commonly used method which copies the application struct into the request...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
11
by: whirlwindkevin | last post by:
I saw a program source code in which a variable is defined in a header file and that header file is included in 2 different C files.When i compile and link the files no error is being thrown.How is...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.