|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
||||
|
||||
|
how 2 use public variables
Hi all,
I'm very new to VB and so it did not last long until the first question occured. In the following code I want to display the four variables in the myFunction function. In the cmdOK_Click routine all values are displayed. In the myFunction function the message box is empty. Thanks in advance Code:
Public Function myFunction() MsgBox (val1 & val2 & val3 & val4) End Sub Private Sub cmdOK_Click() Public val1 As String Public val2 As String Public val3 As String Public val4 As String val1 = field1.Text val2 = field2.Text val3 = field3.Text val4 = field4.Text MsgBox (val1 & val2 & val3 & val4) End Sub |
|
#2
|
||||
|
||||
|
To use public global variables, declare the variables at the top of the form, or in a module.
If you declare them public they will be available everywhere throughout your program, if you declare them private they will be available only in the module/form that you declared them in. i.e. Code:
Option Explicit Public sVal1 As String Public sVal2 as String Public sVal3 as String Public sVal4 as String Public Sub anExample() MsgBox val1 & val2 & val3 & val4 End Sub Private Sub cmdOK_Click() val1 = field1.Text val2 = field2.Text val3 = field3.Text val4 = field4.Text Call anExample End Sub |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > how 2 use public variables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|