Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

**Problem with keeping PUBLIC variable values**

Posted on 1998-11-18
5
Medium Priority
?
146 Views
Last Modified: 2010-05-03
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?????
0
Comment
Question by:idoeisenberg
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1445448
Do you have a local variable with the same name maybe?
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1445449
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.
0
 
LVL 14

Accepted Solution

by:
Matti earned 400 total points
ID: 1445450
Hi!

There is currently very limited information present about the actual problem, but if I catch this.

Lets see if you assing a variable when you load a form
using code Form_load then you assing an other value to the same variable in next Form_load code, if this previous form is already loaded in the memory this Form_load section is never executed in this stage if you call it to load or show again.

The call load do not happen if the form is already loaded and
it won't rise erros either.

You must reconsider where assing those variables, the Form_Activate may be better in this case.

Extra info! Also if you make a call to object whitch is placed on a form whitch is not loaded, 32bit versions of VB loads it automaticly.

Matti!

0
 

Author Comment

by:idoeisenberg
ID: 1445451
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
0
 
LVL 14

Expert Comment

by:Matti
ID: 1445452
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question