Link to home
Start Free TrialLog in
Avatar of idoeisenberg
idoeisenberg

asked on

**Problem with keeping PUBLIC variable values**

Please help folks, I am stumped!
I have a program with 3 forms, and a Module in which I declare several PUBLIC variables. When I move from Form1 to Form2 and on to Form3 they retain their value, but when I change their value in Form3 and return to Form2 - the new value is not kept, and the old value is presented. Why?????
Avatar of Mirkwood
Mirkwood

Do you have a local variable with the same name maybe?
You have to update the values in the user interface to show the new values.
On form_activate, reinitialize the controls on your form with the modified data.
ASKER CERTIFIED SOLUTION
Avatar of Matti
Matti
Flag of Finland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of idoeisenberg

ASKER

mati, thanks for now, (toda achi), but it was hard to understand exactly what to do.
When exactly to use the Form_Activate:
1) when coming back to Form2 after changing the variables in Form3?
2) when loading the forms in the beginning?

Is form_activate instead of Form_Load or Show?

thanks, ido
Hi!

I understand your problem was that form_load event don't
happen if the form is already loaded.

This is one primary cause to such problem like yours.

If you need to assing a variable if it is public it will
keep it's value unless you don't assing it a new value.
There is no such bug in VB

And now the probleem must be that the code placed on form2
don't be executed after entering there from form3 or the
code on form3 is executed after entering to form2

You may debug your code using simple Msgbox trim$(myvariable)
sentences and place these after you assing a value to variable.

Then the Msgbox rises every time the variable has been re assingned you find the error quicly.

Form_Activate is proced everytime the form is activated by the uses or code.

This may not be the best solution in your case, I don't know
if it fit to this purpose or yours.

If this is stil actual send me some extra info about your program.

Matti