pin_plunder
asked on
public variables
I've got this problem...
Form1:
Public Senf As String
Private Sub Command1_Click()
Senf = "es un largo relato"
Form2.Show
End Sub
Form2:
Private Sub Command1_Click()
If Senf = "es un largo relato" Then
Print "it works"
Else
Print "it doesn't"
End If
End Sub
------------------
display: it doesn't
why doesn't this code work?
aren't public variables available throughout the project, in all forms and modules?
please just answer THIS question and don't give me unuseful tips.
thanks for your patience :)
Form1:
Public Senf As String
Private Sub Command1_Click()
Senf = "es un largo relato"
Form2.Show
End Sub
Form2:
Private Sub Command1_Click()
If Senf = "es un largo relato" Then
Print "it works"
Else
Print "it doesn't"
End If
End Sub
------------------
display: it doesn't
why doesn't this code work?
aren't public variables available throughout the project, in all forms and modules?
please just answer THIS question and don't give me unuseful tips.
thanks for your patience :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
One other thing... Instead of doing this on Form2:
If Senf = "es un largo relato" Then
You can try this:
If Form1.Senf = "es un largo relato" Then
and set a break point in the Form1 Load Event. If the load event fires when the Form2 "If" executes, Form1 was unloaded...
Cheers!
If Senf = "es un largo relato" Then
You can try this:
If Form1.Senf = "es un largo relato" Then
and set a break point in the Form1 Load Event. If the load event fires when the Form2 "If" executes, Form1 was unloaded...
Cheers!
If you add a public variable inside a class/form/usercontrol the VB compiler will translate this into a public PROPERTY of the form.
If you add Option Explicit on all the forms you will get a 'variable not defined' error when you try to access the variable from the Form2.
Only public variables in a module is global variables.
If you add Option Explicit on all the forms you will get a 'variable not defined' error when you try to access the variable from the Form2.
Only public variables in a module is global variables.
ASKER
thanks everybody
public senf as string
global senf as string
they both work
is there any difference between them?
may be memory usage or something?
public senf as string
global senf as string
they both work
is there any difference between them?
may be memory usage or something?
ASKER
thanks everybody
public senf as string
global senf as string
they both work
is there any difference between them?
may be memory usage or something?
public senf as string
global senf as string
they both work
is there any difference between them?
may be memory usage or something?
Global and Public are the same, however, Global can only be used in modules...
For example:
Global Senf As String
Will work in a MODULE, but will generate a compile error in a FORM.
Cheers!
For example:
Global Senf As String
Will work in a MODULE, but will generate a compile error in a FORM.
Cheers!
ASKER
thanks.
Public Senf as String
polaughlin