The STATIC statement is valid only inside a Sub or Function. Static variables retain their values even after the Sub or Function ends. A static variable is local to its Sub or Function, and can have the same name as other variables in other parts of the program without conflict.
Public variables let your main form look at properties that have been set from your dialog forms. The Public variable belongs to the dialog form, but by declaring it Public, you allow other modules to look at or set its value. In frmDate in this example, the day of the week goes with the date information entered onto the form. DayofWeek logically belongs to this form. But we want to see that information from elsewhere, so we make it Public.
On the other hand, Private variables are those that are used to make an individual form or module work properly, but it is not necessary to see or set their values from outside the module. In frmDate, we want to initialize its date to today, and we want to remember the last date entered, so we use the Private variables SaveM, SaveD, and SaveY. These variables are used in more than one procedure on the form, so they cannot be strictly local. But we also have no need (as designed) to read or set these values from other modules. So we make them Private.
John
A+ Certified
2006-12-14 03:03:31
·
answer #1
·
answered by A+ Certified Professional 5
·
2⤊
0⤋
Ok Visual Basic is an object oriented language based on the BASIC language. An object can possess a number of variables. A private variable is one that only the object's methods can access and manipulate. Public variables can be modified by methods in other part of the program and not necessarily part of the same object so it can be considered global to the scope of the program or object in the program if using embedded objects. A static variable is one that data remains the same throughout the execution of the program and acts like a constant but not hard coded.
To illistrate this... I use this pseudo object class to illustrate.
Static Z = value or function
OBJ Alpha
Private A
Public B
Method Foo1 ( A = 5 ) ' Valid instruction
Method Foo2 ( B = 10 ) ' Valid instruction
END OBJ
OBJ Beta as object Alpha 'creating an instance of alpha
Beta.B = 5 'Valid instruction
Beta.A = 5 'Invalid instruction because only internal methods can access A
Z can be accessed from any part of the program.
Does this help?
2006-12-14 03:22:06
·
answer #2
·
answered by Dragonlord Warlock 4
·
0⤊
0⤋
Public variables of a classification may well be accessed from non-classification memebers yet inner maximum variables could in uncomplicated terms be utilized with the help of strategies(purposes) declaired interior the class itself. A static variable is a variable that has the comparable fee for all variables of that particualr merchandise it quite is defined in. in case you have a classification stated as B and you create products X and Y (B X,Y) .interior the class definiton you have a static variable P; in case you alter this variable like this X.P=5; Y.P will as nicely grow to be P...Static variables are initialized outdoors the class definition.
2016-10-14 22:34:33
·
answer #3
·
answered by ? 4
·
0⤊
0⤋
If u declare variable in any module using Public keyword this variable is public for u r whole project. If the variable declare in the general section of the form using dim this is public for that individual form only. If u declare variable in any event that variable is private variable. The static means never change.
2006-12-14 03:19:43
·
answer #4
·
answered by dipak 2
·
0⤊
0⤋
A public variable can be used anywhere by any procedure or function in the entire program. Used for a value that you will be reuse several times.
A private variable only exist with one procedure, does not need to be permanent or used elsewhere. Such as the value used to count in a "for" loop. It is used, and then released to free up the memory.
A static variable is a variable that is assigned a value that can not be changed. Such as you might assign a variable for hold the value of "pi" if you were calculate circumferences. The value of pi will never need to change.
2006-12-14 03:07:31
·
answer #5
·
answered by dewcoons 7
·
0⤊
0⤋
A public variable can be used anywhere and a private variable can only bu used in that subroutine. A static variable is can be declared anywhere in the program but usually stays constant throughout the program.
2006-12-14 03:04:20
·
answer #6
·
answered by bourne3141592654 2
·
0⤊
0⤋
1.A Public Variable Can be used in any module.However a Private variable can only be used in the function (or module if you declare it in the general declerations section) in wich it is declared.
2.A static variable does not reset every time the funcion is run.
For example, If you wanted to write a function that returns how many times it has been called you could try this:
Public Function AddOne ()
dim one as integer
one = one + 1
AddOne = one
end function
But, no matter how many times you run this function the result will be 1.
But if you Chanced the One to a Static Variable like this:
Public Function AddOne ()
Static one as integer
one = one + 1
AddOne = one
end function
You would get the correct result.
Hope it helps
LLAP
2006-12-14 03:14:37
·
answer #7
·
answered by James R 2
·
0⤊
0⤋
Public variables are made available to the entire program whereas private variables are only made available to certain parts or subroutines of a program.
A static variable is a constant.
http://www.handlethetruth.net
2006-12-14 03:02:58
·
answer #8
·
answered by truth_handler 3
·
0⤊
0⤋
A public variable (or sub or function) is one that is accessible by all forms and modules of the programme. A private variable is one that is only accessible by the form or module its in.
2006-12-14 03:04:15
·
answer #9
·
answered by Anonymous
·
0⤊
0⤋