Solved

problem with a hidden form

Posted on 2000-04-08
12
162 Views
Last Modified: 2010-05-02
I have an app with four different forms, three of which are usually not displayed (configuration forms). When the user changes a text field on the main form, I need to update a value on a hidded configuration form, so it's correct when the user opens it. But in the frmMain code, when I say something like

frmConfig.actualPosition.text = actualPos

frmConfig becomes visible. The best I've done so far is to immediately hide it again after stuffing the data in it, but I know there must be an easy way to update a forms fields without showing the form. (If it turns out not to be easy, but you know the answer, I'll tack on some extra points.)

Thanks.
0
Comment
Question by:oldbie
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2695795
This means that your configuration form was not loaded yet, thus loading it as soon as you change one of the properties that makes the form issue some painting.
What you need is to load your forms at startup:

---- frmMain.frm ---
private mfrmConfig1 as frmConfig1

Private Sub Form_Load()
  set mfrmConfig1 = new frmConfig1
  'do be sure the form doesn't show
 mfrmConfig1.Visible = false
End sub

Private Sub Form_Unload()
  unload mfrmConfig
  set mfrmConfig = Nothing
End Sub

--------------------
If now you update the property on your form, it won't show up.

Don't worry about points. Real Experts are here to help :-)


0
 
LVL 4

Expert Comment

by:Nazdor
ID: 2695825
AngelIII is correct here, but it's slightly easier - there's no need to create a variable to hold the form, unless you want to open the same form more than once.  So in your main form:

Private Sub Form_Load()
    Load frmConfig
End Sub

Private Sub Form_Unload()
    Unload frmConfig
End Sub


Then, when you want the form to be visible, simply: frmConfig.Visible = true

You must unload any loaded forms though.


The other thing to remember is that when frmConfig tries to close, it mustn't actually close - merely become visible=false, so in frmConfig you also need:

Private Sub Form_Unload(Cancel As Integer)
    Me.Visible = False
    Cancel = True
End Sub


Otherwise you'll be back to where you were before with the second time the form gets accessed it pops up.

Perhaps that's where using a variable will help - not tried it out.


---

The alternative would be to load your settings in the Form_Load of frmConfig so that you're not continuously copying data across, just once when the form loads.  But I doubt there's much of a performance difference either way.
0
 

Expert Comment

by:MSOFT100
ID: 2695956
Have you tried with
frmConfig.Visible=False
before you do
frmConfig.actualPosition.text = actualPos

This should be enough.
0
Technology Partners: 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!

 
LVL 1

Expert Comment

by:cchenoweth
ID: 2696527
If the Program is a MDI form and has MDI children you need to go to the main MDI form and turn off the property Autoshowchildren.

Just a thought.
0
 

Author Comment

by:oldbie
ID: 2696544
Something that might not have been clear: frmConfig can be visible or not, by the user's choice, and I need to update the field either way.

Loading the form in frmMain's Load and then hiding it makes frmConfig flash visible and then disappear. Looks unprofessional. And I'm getting paid for this, so I'm a professional, right? hmmm.

So, to refine the problem description: The main form has a button which displays the config forms. The config forms have fields on them that need to be updated as the situation in the external world changes, whether or not those config forms are displayed at the moment, so that when they are displayed, the data will be correct. And I don't want any forms flashing for a split-second as they're loaded and then hidden.

Thanks for your help!
0
 
LVL 14

Accepted Solution

by:
wsh2 earned 20 total points
ID: 2696655
No way does this statement cause the Form to SHOW..

   frmConfig.actualPosition.text = actualPos

A reference merely causes the Form to load.. NOT display.. change all the frmConfig items you want.. but it is not until you do a frmConfig.Show or a frmConfig.Visible = True will it display!!! (An MDI Parent being the exception).

Oldbie.. long story short.. you have a logic problem. Single step through your program.. and you will see that a frmConfig.Visible and/or Show is happening when you don't want it to.. <smile>.

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2696900
wsh2: i think that you are wrong.
if a form was not loaded, and you issue a change to one of the properties that need painting, the form will load AND show (if visible property is set true as default) Try it (smile)
0
 

Author Comment

by:oldbie
ID: 2697305
wsh2, you are right. (I'll bet it's fun to always be right!)

Poltergeists snuck a Me.Show into the form load sub. I took it out and everything works like it should.

When I think of the time I wasted looking in all the wrong places .... <sigh>

Thanks. Have some points.

~~~~~~~~~~~~~

angelIII, you are wrong. Try it. I did.

Form1 with two buttons:

Private Sub Command1_Click()
  ' put date and time in text box on other form
  frmOther!Text1.Text = Now
End Sub

Private Sub Command2_Click()
  frmOther.Show
End Sub

frmOther with a lonely text box, saying "Text1".

Run the prog, click command1 button. Nothing (visible) happens. Click command2 button. Text box magically has current date and time in it.

0
 
LVL 14

Expert Comment

by:wsh2
ID: 2697437
oldbie.. Thank you for the always right compliment.. I am a "MAN" afterall.. <running and ducking from AngelIII.. lol.. just kidding>.

Changing a textbox is not necessarily a good test of what AngelIII is purporting, as there is no repaint involved. Now that I am here.. I guess I should check it out. Be Right Back.. <smile>. Ok.. I added a Form2.Move statement in Form1.. and then added a Form2.Circle method after that.. and executed the code with Form2 Autodraw = to True and then False.. Form2 never appeared.. as it should not.

Now, in all fairness, I am using VB6(SP3) on a Win95 PC to test this. Perhaps with a different version of VB or different Operating system environment the behaviour that AngelIII alludes to, will happen.. it just didn't happen here.

Having visited with AngelIII in other threads, she seems to be a very knowledgable Expert.. as such, I have always held her comments in high regard.. <smile>.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2699125
Hi wsh2, commenting the "SHE", but ... I'm a "MAN" too (grin)
I'will check my previous comment regarding the form behaviour...

CUL8R
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2699192
AngelIII:
What MAN is an "Angel" when it comes to Form and Behaviour?... <lol> and a <smile>.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2699195
I'm
0

Featured Post

Industry Leaders: 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

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…
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…
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…
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…

756 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