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
Solved

**Problem with keeping PUBLIC variable values**

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB error "Type mismatch" 2 59
clicking a shape in a frame array vb6 3 46
Help me. 3 60
checkbox to hide entire section 10 40
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we 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…
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…

791 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