oui j'ai corrigé je saisMsgBox Classe.Child(2).CallerUserForm.Classe.Name -> nom de la classe mère
MsgBox Me.Classe.Child(2).Name -> nom de la classe fille
Ce n'est pas du tout la même chose.
CallerUserForm.Classe référence la classe mère, celle-là:
Regarde la pièce jointe 1204234
tu a tout disC'est comme si tu faisais UserForm1.Classe
Alors je n'ai pas eu ce cas dans le code Exit/Enter mais c'est possible puisque dans toutes les instances filles tu as accès à l'instance mère (celle Public du UserForm) qui stocke toutes les instances filles dans sa Collection Child.donne un age a la fille(2) par exemple et de la lire dans la classe de la fille(3)
Si tu ne peux pas passer par l'instance mère (celle Public du UserForm) tu ne peux rien faire car aucun lien n'existe entre les filles. Et la liste des filles n'est connue que de l'instance mère du UserForm via la Collection Child.et cela dans la classe sans aller chercher le userform
Encore que si on voulait vraiment chercher l'embrouille, il y a un lien entre l'instance mère du UserForm et les instances filles qui sont dans la collection de l'instance mère.Dans le fichier du post #39, toutes les instances mère et filles se terminent automatiquement à la fermeture du UserForm précisément parce qu'il n'y a aucun lien croisé d'instances.
voila...!! on y arriveSi tu ne peux pas passer par l'instance mère (celle Public du UserForm) tu ne peux rien faire car aucun lien n'existe entre les filles. Et la liste des filles n'est connue que de l'instance mère du UserForm via la Collection Child.
Oui mais avec ton modèle, la fermeture du UserForm ne termine par automatiquement les instances, faut coder.avec mon modele oui
Public WithEvents TXTB As MSForms.TextBox
Public child As New Collection
Public OldControl As Object
Public uf As UserForm
Public nam As String
Public Function init(usf As UserForm)
Dim cla As Classe1
For Each ctrl In usf.Controls
Set cla = New Classe1
Set cla.TXTB = ctrl
Set cla.uf = usf
cla.nam = ctrl.Name
Set Me.OldControl = usf.Controls(0)
Me.child.Add cla
Next
'MsgBox uf.classe.nam
End Function
Private Sub TXTB_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub TXTB_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub resultat()
Dim ControlIn As Object, ControlOut As Object
Set ControlIn = uf.ActiveControl
Set ControlOut = uf.ClaSSe.OldControl 'paff!! ca plante ici
'envoie aux pseudo events
If Not uf.ClaSSe.ControlOut Is Nothing Then
If ControlIn.Name <> ControlOut.Name Then
Control_Exit uf.Controls(ControlOut.Name)
Control_Enter uf.Controls(ControlIn.Name)
End If
End If
'on met a jour oldcontrol avec le control actif pour le prochain tour
Set uf.ClaSSe.OldControl = ControlIn
End Sub
'les faux events Exit et Enter
Sub Control_Enter(ctrlY)
Cells(Rows.Count, 1).End(xlUp).Offset(1) = " Enter : " & ctrlY.Name
End Sub
Sub Control_Exit(ctrlX)
Cells(Rows.Count, 1).End(xlUp).Offset(1) = " Exit : " & ctrlX.Name
End Sub
Private Sub Class_Initialize()
End Sub
Private Sub Class_Terminate()
Cells(Rows.Count, 1).End(xlUp).Offset(1) = "classe " & Me.nam & " terminée"
End Sub
Public ClaSSe As Classe1
Private Sub UserForm_Activate()
Set ClaSSe = New Classe1
ClaSSe.nam = "mère"
Me.ClaSSe.init Me
End Sub
Public WithEvents TXTB As MSForms.TextBox
Public child As New Collection
Public OldControl As Object
Public uf As Object
Public nam As String
Public Function init(usf As Object)
Dim cla As Classe1
For Each ctrl In usf.Controls
Set cla = New Classe1
Set cla.TXTB = ctrl
Set cla.uf = usf
cla.nam = ctrl.Name
Set Me.OldControl = cla.uf.Controls(0)
Me.child.Add cla
Next
'MsgBox uf.classe.nam
End Function
Private Sub TXTB_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub TXTB_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub resultat()
Dim ControlIn As Object, ControlOut As Object
Set ControlIn = uf.ActiveControl
Set ControlOut = uf.ClaSSe.OldControl 'paff!! ca plante ici
'envoie aux pseudo events
If Not ControlOut Is Nothing Then
If ControlIn.Name <> ControlOut.Name Then
Control_Exit uf.Controls(ControlOut.Name)
Control_Enter uf.Controls(ControlIn.Name)
End If
End If
'on met a jour oldcontrol avec le control actif pour le prochain tour
Set uf.ClaSSe.OldControl = ControlIn
End Sub
'les faux events Exit et Enter
Sub Control_Enter(ctrlY)
Cells(Rows.Count, 1).End(xlUp).Offset(1) = " Enter : " & ctrlY.Name
End Sub
Sub Control_Exit(ctrlX)
Cells(Rows.Count, 1).End(xlUp).Offset(1) = " Exit : " & ctrlX.Name
End Sub
Private Sub Class_Initialize()
End Sub
Private Sub Class_Terminate()
Cells(Rows.Count, 1).End(xlUp).Offset(1) = "classe " & Me.nam & " terminée"
End Sub
Option Explicit
Public WithEvents TXTB As msforms.TextBox
Public WithEvents bouton As msforms.CommandButton
Public WithEvents opt As msforms.OptionButton
Public WithEvents Check As msforms.CheckBox
Public WithEvents toggle As msforms.ToggleButton
Public WithEvents LstBox As msforms.ListBox
Public WithEvents Combo As msforms.ComboBox
Public WithEvents Image As msforms.Image
Public WithEvents spin As msforms.SpinButton
Public WithEvents multi As msforms.MultiPage
Public WithEvents fram As msforms.Frame
Public WithEvents forme As UserForm
'Public WithEvents lsView As msforms.ListView
Public child As New Collection
Public OldControl As Object
Public uf As Object
Public nam As String
Public Function init(usf As Object)
Dim cla As Classe1, CtrL
For Each CtrL In usf.Controls
Set cla = New Classe1
If TypeOf CtrL Is TextBox Or TypeName(CtrL) = "TextBox" Then: Set cla.TXTB = CtrL: CtrL.Value = CtrL.Name
If TypeOf CtrL Is OptionButton Or TypeName(CtrL) = "OptionButton" Then Set cla.opt = CtrL
If TypeOf CtrL Is CommandButton Or TypeName(CtrL) = "CommandButton" Then Set cla.bouton = CtrL
If TypeOf CtrL Is CheckBox Or TypeName(CtrL) = "CheckBox" Then Set cla.Check = CtrL
If TypeOf CtrL Is ToggleButton Or TypeName(CtrL) = "ToggleButton" Then Set cla.toggle = CtrL
If TypeOf CtrL Is ListBox Or TypeName(CtrL) = "ListBox" Then Set cla.LstBox = CtrL
If TypeOf CtrL Is ComboBox Or TypeName(CtrL) = "Combobox" Then Set cla.Combo = CtrL
If TypeOf CtrL Is Image Or TypeName(CtrL) = "Image" Then Set cla.Image = CtrL
If TypeOf CtrL Is Frame Or TypeName(CtrL) = "Frame" Then Set cla.fram = CtrL
If TypeOf CtrL Is SpinButton Or TypeName(CtrL) = "SpinButton" Then Set cla.spin = CtrL
If TypeOf CtrL Is MultiPage Or TypeName(CtrL) = "multipage" Then Set cla.multi = CtrL
Set cla.uf = usf
cla.nam = CtrL.Name
Set Me.OldControl = cla.uf.Controls(0)
Me.child.Add cla
Next
End Function
Private Sub TXTB_KeyUp(ByVal KeyCode As msforms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub opt_KeyUp(ByVal KeyCode As msforms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub bouton_KeyUp(ByVal KeyCode As msforms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub Combo_KeyUp(ByVal KeyCode As msforms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub LstBox_KeyUp(ByVal KeyCode As msforms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub image_KeyUp(ByVal KeyCode As msforms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub toggle_KeyUp(ByVal KeyCode As msforms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub Check_KeyUp(ByVal KeyCode As msforms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub spin_KeyUp(ByVal KeyCode As msforms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub LsView_KeyUp(KeyCode As Integer, ByVal Shift As Integer): resultat: End Sub
'les events mouse_Down
Private Sub bouton_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub opt_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub TXTB_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub LstBox_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub Combo_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub toggle_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub Check_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub image_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub Multi_MouseDown(ByVal Index As Long, ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub fram_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub LsView_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS): resultat: End Sub
Private Sub Spin_SpinDown(): resultat: End Sub
Private Sub Spin_SpinUp(): resultat: End Sub
Private Sub resultat()
Dim ControlIn As Object, ControlOut As Object
Set ControlIn = uf.ActiveControl
Set ControlOut = uf.ClaSSe.OldControl 'paff!! ca plante ici
'envoie aux pseudo events
If Not ControlOut Is Nothing Then
If ControlIn.Name <> ControlOut.Name Then
Control_Exit uf.Controls(ControlOut.Name)
Control_Enter uf.Controls(ControlIn.Name)
End If
End If
'on met a jour oldcontrol avec le control actif pour le prochain tour
Set uf.ClaSSe.OldControl = ControlIn
End Sub
'les faux events Exit et Enter
Sub Control_Enter(ctrlY)
Cells(Rows.Count, 1).End(xlUp).Offset(1) = " Enter : " & ctrlY.Name
End Sub
Sub Control_Exit(ctrlX)
Cells(Rows.Count, 1).End(xlUp).Offset(1) = " Exit : " & ctrlX.Name
End Sub
Private Sub Class_Initialize()
End Sub
Private Sub Class_Terminate()
Cells(Rows.Count, 1).End(xlUp).Offset(1) = "classe " & Me.nam & " terminée"
End Sub
Private Sub resultat()
Dim ControlIn As Object, ControlOut As Object
Set ControlIn = uf.ActiveControl
Set ControlOut = uf.ClaSSe.OldControl 'paff!! ca plante ici
'envoie aux pseudo events
If Not ControlOut Is Nothing Then
If ControlIn.Name <> ControlOut.Name Then
If TypeName(ControlOut) = "TextBox" Then Control_Exit uf.Controls(ControlOut.Name)
If TypeName(ControlIn) = "TextBox" Then Control_Enter uf.Controls(ControlIn.Name)
End If
End If
'on met a jour oldcontrol avec le control actif pour le prochain tour
Set uf.ClaSSe.OldControl = ControlIn
End Sub