Solved

**Problem with keeping PUBLIC variable values**

Posted on 1998-11-18
5
142 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 100 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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