Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell if a form is open?

Status
Not open for further replies.

RichS

Programmer
Apr 24, 2000
380
US
Hello all,
I am using the MSComm control on a MDI form. This control captures the weight from a large truck scale. The weight is transmitted about once every second. When the weight is above 500 lbs I have a form that pops up and asks the user for the LOAD TYPE (Inbound or Outbound). One of two other forms are shown based on the answer. In these last two forms - which ever one is selected - I put the weight in a text box and allow the user to save it (and other info) to a database.

I need the MDI to be able to evaluate what is going on in the other 3 forms so as to not continually try show the LOAD TYPE form until the weight is captured and the truck has left the scale.

What is the best way to evaluate whether a form is open and in use from another form?
 
Detect If Form Is Already Loaded

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Add 2 Command Buttons to your form. Add Another Form (Form 2).
'Click on the first button, and the program will detect that Form2 is not loaded.
'Now click on the second button to load Form2 and click again on the first button.
'The program will dedtect that Form2 is now loaded.
'Insert the following code to your module:

Public Function FormLoadedByName(FormName As String) As Boolean
Dim i As Integer, fnamelc As String
fnamelc = LCase$(FormName)
FormLoadedByName = False
For i = 0 To Forms.Count - 1
If LCase$(Forms(i).Name) = fnamelc Then
FormLoadedByName = True
Exit Function
End If
Next
End Function

'Insert the following code to your form (Form1):

Private Sub Command1_Click()
'Replace 'Form2' with the name of the form you want to detect his state.
If FormLoadedByName("Form2") = True Then
MsgBox "The Form is loaded"
Else
MsgBox "The Form is not loaded"
End If
End Sub

Private Sub Command2_Click()
Load Form2
End Sub


Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX.

Download Demo version on my Site:
Promotions before 02/28/2001 (free source codebook),visite my site
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top