Solved

**Problem with keeping PUBLIC variable values**

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now