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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Form Instance Identification at Runtime

Status
Not open for further replies.

clawton

Technical User
Jul 23, 2000
27
0
0
GB
Apologies in advance if this is Kindergarten stuff, but I'm really struggling on this one...

I'm developing an app with an MDI Form as it's main window. On startup, I dynamically create a varying number of MDIChild forms, dependent on data stored elsewhere. I use the following code within the FORM_LOAD section of my MDIForm:

Dim a As Form
For Counter = 0 To Form2.List1.ListCount - 1
Set a = New CallGroupForm
a.FormNumber = FormNumber
FormNumber = FormNumber + 1
a.Visible = True
Next Counter

(a.FormNumber and a.Visible are used for other purposes, and are not really part of the problem).

Within each MDIChild that is generated in this way, I can control each window form from within itself using the 'Me.' predicate.

My problem is, how do I identify and control one of the form instances from code external to the individual form? For example, using code elsewhere in the app, I need to unload a single instance of the Form, leaving all others in place. Unfortunately, the FormName for every instance is the same - 'CallGroupForm, and trying to change the FormName at runtime returns an error.

Do I have to do something clever with the WindowHandle, or is there a simpler solution.

Thanks in advance.




Chris Lawton
Chris@Lawton.net

 
Hi Chris,

what about the FormNumber then? Isn't it unique for each form? I would suggest using that as (I assume that FormNumber is a public variable of CallGroupForm):

Dim frm as Form
For Each frm In VB.Forms
If frm.Name = "CallGroupForm" Then
If frm.FormNumber = <the number you wish to unload> Then Unload frm
End If
Next

nicsin
 
Dim x(20) As New CallGroupForm
Dim FormNumber As Integer

Private Sub dddd_Click()
Load x(FormNumber)
x(FormNumber).Caption = &quot;Form &quot; & FormNumber
FormNumber = FormNumber + 1
End Sub

Hope that helps!
 
Dim x(20) As New CallGroupForm
Dim FormNumber As Integer

Private Sub Command1_Click()
Load x(FormNumber)
x(FormNumber).Caption = &quot;Form &quot; & FormNumber
x.Tag = FormNumber
FormNumber = FormNumber + 1
End Sub

Private Sub Command2_Click()
On Error Resume Next
MsgBox &quot;Form x&quot; & (ActiveForm.Tag) & &quot; is Active&quot;
End Sub

 
Dim x(20) As New CallGroupForm
Dim FormNumber As Integer

Private Sub Command1_Click()
Load x(FormNumber)
x(FormNumber).Caption = &quot;Form &quot; & FormNumber
x(FormNumber).Tag = FormNumber
FormNumber = FormNumber + 1
End Sub

Private Sub Command2_Click()
On Error Resume Next
MsgBox &quot;Form x(&quot; & (ActiveForm.Tag) & &quot;) is Active&quot;
End Sub

Sorry for messin' up your box!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top