1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
Option Explicit
' Collection contenant les instances de classe
Private TextBoxCollection As Collection
Private Sub UserForm_Initialize()
'Dim loCtl As Control
Dim Ctrl As Control
Dim TextBoxInstance As TextBoxClasse
' Initialise la collection
Set TextBoxCollection = New Collection
' Boucle sur les contrôles
For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "TextBox" Then
' Nouvelle instance de classe
Set TextBoxInstance = New TextBoxClasse
' Initialise la TextBox dans l'instance de classe
Set TextBoxInstance.TextBoxEvent = Ctrl
' Ajoute l'instance de classe à la collection
' Etape importante pour qu'elle ne soit pas détruit ensuite
TextBoxCollection.Add TextBoxInstance
End If
Next
End Sub
' Méthode publique recevant les notifications de modifications de textbox
' en provenance des instances
Public Sub TextBoxVerifNum_Change(KeyAscii As MSForms.ReturnInteger)
If InStr("1234567890,-", Chr(KeyAscii)) = 0 Or groupebouton.SelStart > 0 And Chr(KeyAscii) = "-" _
Or InStr(groupebouton.Value, ",") <> 0 And Chr(KeyAscii) = "," Then
KeyAscii = 0: Beep
End If
End Sub |
Partager