Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

**Problem with keeping PUBLIC variable values**

Posted on 1998-11-18
5
Medium Priority
?
145 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

618 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