GLOBAL AND LOCAL VARIABLES
Global variables are approached by any function that is part of the main program. They are put intoplay by combining memory locations with the names of the variable. Unlike local variables, globalvariables do not come back into play each time the function has been called back. Global variablesare used when you need the value outside of the scope that it was originally created in.
Local variables are only existent within the exact function that creates them. They are otherwiseunknown to the other functions and the main program. Local variables stop once the function whichcreated them has been ended. They do however come back into play each time the function has beenexecuted. A local variable only exists for its scope. Local variables are usually only needed in onesection of code and are only modified within that section.
Global and variables declared in my programs
Global and local variables that were included in my UCAS calculator included the following:DimPassUnitPoints As Integer DimMeritUnitPoints As Integer DimDistinctionUnitPoints As Integer The above are examples of local variables that have been declared inside of a subsided module.They are only used within that specific module.Global and local variables that were included within my notesaver included the following:Dimsaverfile1 As NewSaveFileDialogue
saverfile1.DefaultExt ="*.doc"The above are examples of local variables in my notesaver, known as procedural variables. Thereason for this is that it is not limited to a certain section of the program, instead it can be usedanywhere in the program
Scope of Variables
The scope looks at the visibility of a variable, where it is in the program, can it be seen and used. Anexample could be that in my note saver program:
Dimsaverfile1 As NewSaveFileDialogue
saverfile1.DefaultExt ="*.doc´,The above variable is declared inside of the event handler and can only be used inside of that eventhandler; it does not exist outside of it. This is a local variable. A variable that is declared within the form class can initially be used within the event handlers, it willhave a wider scope.