• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

problem with a hidden form

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
oldbie
Asked:
oldbie
  • 4
  • 3
  • 2
  • +3
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
NazdorCommented:
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
 
MSOFT100Commented:
Have you tried with
frmConfig.Visible=False
before you do
frmConfig.actualPosition.text = actualPos

This should be enough.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
cchenowethCommented:
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
 
oldbieAuthor Commented:
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
 
wsh2Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
oldbieAuthor Commented:
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
 
wsh2Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Hi wsh2, commenting the "SHE", but ... I'm a "MAN" too (grin)
I'will check my previous comment regarding the form behaviour...

CUL8R
0
 
wsh2Commented:
AngelIII:
What MAN is an "Angel" when it comes to Form and Behaviour?... <lol> and a <smile>.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I'm
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.

  • 4
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now