[global variables]

FantasiaDown
09-11-2003, 11:02 AM
[hey there]

so, the problem i had before concerning reading a sequential file (from the mnu_file click event yet again) has improved and for the most part, finally have the majority of it understood.

the only thing i'm really having problems with now is to change the input information into global variables and then have the information displayed on the appropriate form? how do i go abouts coding global variables?

this is what i have..

Private Sub mnuEdit_Click()
Dim strLName As String, strFName As String, strAddress As String, intApartment As String, strCity As String, strProvince As String, strPostal As String, strMemo As String
Const conprompt As String = "Enter the Contact's Last Name"
Const contitle As String = "Contact's Last Name"
strInput = InputBox(contitle, conprompt)
Dim strfilename As String
strfilename = App.Path & "contact.dat"
Open App.Path & "contact.dat" For Input As #1 'open sequential file
Do While Not EOF(1)
Input #1, strInput, strFName, strAddress, strApartment, strCity, strProvince, strPostal, strMemo 'read in from file


Loop
Close #1 'close file


any help would be great.

CArNi4
09-11-2003, 11:06 AM
To use global variables you just add a module to your project. In the Option Explicit part of the module you can declare global variables:
Global strString As String

passel
09-11-2003, 11:07 AM
Just move your "Dim" statements into the general Declarations area, and
then the variables are "Global" to that form, which means all your subs
and functions and event handlers can seem them in this form.

If you have multiple forms, add a .bas module, and declare the variables Public in the .bas module, then every part of you program
can see those variables.

The use of the term "Public", is preferred to the use of "Global". "Global"
is left over from legacy Basic, and will not be supported in later versions
of Visual Basic, such as .Net

reboot
09-12-2003, 08:32 AM
I don't see how he could have explained it much better. Exactly which part did you not understand?

SnakeChomp
09-12-2003, 08:38 AM
Do you mean public as in everything in your entire program can access the variable? Or public as in every function in your form can access it?
The former: Add a module to your project and dim variables inside of it like "public <name> <type>"
The latter: The very top of your code, where it should say Option Explicit if you have it turned on, is where the general declarations section is. Any variables dim'd up here will be accessible by any function or sub inside of your form.

FantasiaDown
09-12-2003, 08:58 AM
So, i added a Module and put this in under Option Explicit - i hope its alright...

Option Explicit
Public strLName As String, strFName As String, strAddress As String, intApartment As String, strCity As String, strProvince As String, strPostal As String, strMemo As String

one question i have is : is this statement removed or just copied from the original frm i got it from? what else would i need to include in that module?

thank you.





Do you mean public as in everything in your entire program can access the variable? Or public as in every function in your form can access it?
The former: Add a module to your project and dim variables inside of it like "public <name> <type>"
The latter: The very top of your code, where it should say Option Explicit if you have it turned on, is where the general declarations section is. Any variables dim'd up here will be accessible by any function or sub inside of your form.

SnakeChomp
09-12-2003, 09:04 AM
What do you mean "is the statement removed from the original form." What statement? You don't have to do anything else inside of a module to get public variables other than creating the public variables as you have done. You don't need to put anything else anywhere to have access to those variables.

FantasiaDown
09-12-2003, 09:08 AM
haha.well thank you.
i've only been doing this for a couple of months so i only know what i'm doin half he time.I need this experience and be able to ask questions on just about anything i'm not sure of so i can become the best i can be at programming.



What do you mean "is the statement removed from the original form." What statement? You don't have to do anything else inside of a module to get public variables other than creating the public variables as you have done. You don't need to put anything else anywhere to have access to those variables.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum