Quote:
> On Tue, 24 Jun 2003 17:07:39 +0000 (UTC),
> >Ok, this is going to sound convoluted
> Convoluted is more like a Litote ;-)
> Here's what I ran a test with.. (doesn't work)
I think you can do away with the array counting and
loop the forms for the index and pass the main class ref to the child forms
for the child to send back events. Having played with your code, I think
this is the type of method that is being spoken of in the thread.
--
Geoff
Quote:
> ************Form1 Code:***********
Option Explicit
Public WithEvents cChildWatch As Class1 'This creates One Instance
Private Sub cChildWatch_ActiveChild(Index As Integer)
Dim x As Integer 'Child has Alerted Activate so change command color
For x = 0 To Command1.Count - 1
If x = Index Then
Command1(x).BackColor = vbYellow
Else
Command1(x).BackColor = &H8000000F
End If
Next
End Sub
Private Sub cChildWatch_ColorChange(Index As Integer, ShowColor As
ColorConstants)
'Child alerted color change
Label1(Index).BackColor = ShowColor
End Sub
Private Sub Form_Activate()
Dim x%
For x = 0 To Command1.Count - 1
Command1(x).BackColor = &H8000000F
Next
End Sub
Private Sub Form_Initialize()
Dim x%
For x = 0 To Command1.Count - 1
If Not Command1(x).Style = vbButtonGraphical Then
MsgBox "For full effect the command buttons style need to be
graphical", vbInformation
Exit Sub
End If
Next
For x = 0 To Label1.Count - 1
Label1(x).BackColor = vbRed
Next
End Sub
Private Sub Form_Load()
Set cChildWatch = New Class1
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim frm As Form
For Each frm In Forms
Unload frm
Next frm
End Sub
Private Sub Command1_Click(Index As Integer)
'you could put these in there own collection
'Set/Referenced by index key it saves array management or looping
'all the forms in the application and testing for the correct form
'as it does here.
Dim F As Form
For Each F In Forms 'loop all forms
If F.Name = "Form2" Then 'see if its a form2
If F.MyNum = Index Then ' see if its the index we want
F.SetFocus
Exit Sub
End If
End If
Next
'Not got a form with that index (create one)
Set F = New Form2
InitalizeForm2 F, Index
End Sub
Private Sub InitalizeForm2(frm As Form, Index As Integer)
With frm
'Give F a reference to myWatch
Call .FormWatch(cChildWatch)
.Caption = "SubForm - " & CStr(Index + 1)
.MyNumber = Index
.Top = Me.Top + Index * .Height
.Left = Me.Left + Me.Width + 60
.Show vbModeless, Me
End With
End Sub
Quote:
> *************Form2 Code:*****************
Public Property Let MyNumber(lMyNum As Integer)
mlMyNum = lMyNum
Call cMyClass.ChangeStatusColour(lMyNum, vbGreen)
End Property
Public Sub FormWatch(objWatch As Class1)
Set cMyClass = objWatch
End Sub
Private Sub Form_Activate()
If Not cMyClass Is Nothing Then
'all calls to cmyclass should be checked first
' in case its not been set.
Call cMyClass.AlertActive(mlMyNum)
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call cMyClass.ChangeStatusColour(mlMyNum, vbRed)
End Sub
Private Sub Form_Terminate()
Set cMyClass = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set Form2 = Nothing
End Sub
Quote:
> **************Class Code::*************
Option Explicit
Event ColorChange(Index As Integer, ShowColor As ColorConstants)
Event ActiveChild(Index As Integer)
Public Sub ChangeStatusColour(Index As Integer, MyColor As ColorConstants)
RaiseEvent ColorChange(Index, MyColor)
End Sub
Public Sub AlertActive(Index As Integer)
RaiseEvent ActiveChild(Index)
End Sub