Solved

problem with a hidden form

Posted on 2000-04-08
12
154 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 142

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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 142

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 142

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 142

Expert Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

705 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

17 Experts available now in Live!

Get 1:1 Help Now