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   :)
pin_plunderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

polaughlinCommented:
Placing the 'Senf' declaration in a module works for me.

Public Senf as String

polaughlin
0
mcriderCommented:
If Form1 is unloaded, then the public variable Senf will go away...

Add a MODULE to your project and declare Senf this way:

   Global Senf As String


That way, you don't have to worry about the form being unloaded...


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mcriderCommented:
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!
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

VbmasterCommented:
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.

0
pin_plunderAuthor Commented:
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?

0
pin_plunderAuthor Commented:
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?

0
mcriderCommented:
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!
0
pin_plunderAuthor Commented:
thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.