j'ai compris le fonctionnement. mais c'est le mot optionnel je ne connais pas le sens.
en fait un peu cmme une permutation en probabilité.
Version imprimable
j'ai compris le fonctionnement. mais c'est le mot optionnel je ne connais pas le sens.
en fait un peu cmme une permutation en probabilité.
non paramètres facultatif.
on a A qui par défaut vaut 1, B qui par défaut vaut 2, et c dont on passe "TOTO" en paramètre Optionel C:="TOTO".
Sub Optionel(Optional A As String = "1", Optional B As String = "2", Optional C As String = "3")
MsgBox A & B & C
End Sub
Optionel A:="C", B:= "B",C:= "A"
Optionel C:="A", B:="B", A:="C"
C'est la même chose
A:= c'est le paramètre de la fonction et "A" la valeur
Optionel C:="La variabe C ", B:="La variable B, ", A:="La variabe A, "
mémorisé. merci
je vais essyer maintenant d'étudier la fonction" for each as controls" en profondeur car ça me rend malade lorsque je dois écrire procédure par procédure pour plusieurs controls:roll::roll::calim2::calim2::toutcasse::toutcasse::toutcasse::toutcasse::toutcasse:
Code:
1
2
3
4
5
6
7
8
9
10 Dim Cs() As New TheControl Private Sub UserForm_Initialize() For i = 0 To Me.Controls.Count - 1 ReDim Preserve Cs(i) Cs(i).Objet = Controls(i) Next For i = 0 To UBound(Cs) Debug.Print i, Cs(i).Objet.Name Next End Sub
Code:
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 Private WithEvents Lb As MSForms.Label Private WithEvents Tb As MSForms.TextBox Private WithEvents Cb As MSForms.ComboBox Private WithEvents Ls As MSForms.ListBox Private WithEvents Chb As MSForms.CheckBox Private WithEvents Gb As MSForms.ToggleButton Private WithEvents Fm As MSForms.Frame Private WithEvents Cm As MSForms.CommandButton Private WithEvents Mp As MSForms.MultiPage Private WithEvents Sc As MSForms.ScrollBar Private WithEvents Im As MSForms.Image Private ctrName As String Public Property Let Objet(value As Object) ctrName = TypeName(value) Select Case ctrName Case "Label": Set Lb = value Case "TextBox": Set Tb = value Case "ComboBox": Set Cb = value Case "ListBox": Set Ls = value Case "CheckBox": Set Chb = value Case "ToggleButton": Set Gb = value Case "Frame": Set Fm = value Case "CommandButton": Set Cm = value Case "MultiPage": Set Mp = value Case "ScrollBar": Set Sc = value Case "Image": Set Im = value End Select End Property Public Property Get Objet() As Object Select Case ctrName Case "Label": Set Objet = Lb Case "TextBox": Set Objet = Tb Case "ComboBox": Set Objet = Cb Case "ListBox": Set Objet = Ls Case "CheckBox": Set Objet = Chb Case "ToggleButton": Set Objet = Gb Case "Frame": Set Objet = Fm Case "CommandButton": Set Objet = Cm Case "MultiPage": Set Objet = Mp Case "ScrollBar": Set Objet = Sc Case "Image": Set Objet = Im End Select End Property
:merci::merci::merci::merci::merci::merci::merci::king:
suis soulagé. c'est ce que je cherchais comme demo et comme canevas de code. :piou::piou::love:
salut dysorthographie
j'ai essayé d'ecrire ce petit code dans userform_initializemais le message affiche :objet requisCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 Dim txt As TextBox, cmd As CommandButton For Each txt In page3.Controls For Each cmd In Frame3.Controls Select Case TypeName(txt) Case txt If txt.Value <> "" Then cmd.Enabled = False Else cmd.Enabled = True End If End Select Next Next
quel est le probleme?
Bonsoir,
Code:
1
2
3
4
5
6
7
8 Dim Cs() As New TheControl Private Sub UserForm_Initialize() For i = 0 To Me.Controls.Count - 1 ReDim Preserve Cs(i) Cs(i).Objet = Controls(i) If TypeName(Cs(i).Objet) = "CommandButton" Then Cs(i).Objet.Enabled = False Next End Sub
Code:
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62 Private WithEvents Lb As MSForms.Label Private WithEvents Tb As MSForms.TextBox Private WithEvents Cb As MSForms.ComboBox Private WithEvents Ls As MSForms.ListBox Private WithEvents Chb As MSForms.CheckBox Private WithEvents Gb As MSForms.ToggleButton Private WithEvents Fm As MSForms.Frame Private WithEvents Cm As MSForms.CommandButton Private WithEvents Mp As MSForms.MultiPage Private WithEvents Sc As MSForms.ScrollBar Private WithEvents Im As MSForms.Image Private ctrName As String Public Property Let Objet(value As Object) ctrName = TypeName(value) Select Case ctrName Case "Label": Set Lb = value Case "TextBox": Set Tb = value Case "ComboBox": Set Cb = value Case "ListBox": Set Ls = value Case "CheckBox": Set Chb = value Case "ToggleButton": Set Gb = value Case "Frame": Set Fm = value Case "CommandButton": Set Cm = value Case "MultiPage": Set Mp = value Case "ScrollBar": Set Sc = value Case "Image": Set Im = value End Select End Property Public Property Get Objet() As Object Select Case ctrName Case "Label": Set Objet = Lb Case "TextBox": Set Objet = Tb Case "ComboBox": Set Objet = Cb Case "ListBox": Set Objet = Ls Case "CheckBox": Set Objet = Chb Case "ToggleButton": Set Objet = Gb Case "Frame": Set Objet = Fm Case "CommandButton": Set Objet = Cm Case "MultiPage": Set Objet = Mp Case "ScrollBar": Set Objet = Sc Case "Image": Set Objet = Im End Select End Property Private Sub Tb_Change() Dim Changer As Boolean If Trim(Tb.Parent.Name) = "Frame3" Then If Trim(Tb.Parent.Parent.Name) = "Page3" Then For Each txt In Tb.Parent.Controls Debug.Print TypeName(txt) If TypeName(txt) = "TextBox" Then If txt <> "" Then Changer = True: Exit For End If Next For Each cmd In Tb.Parent.Controls If TypeName(cmd) = "CommandButton" Then cmd.Enabled = Changer Next End If End If End Sub
ok.merci. javais relu ton ancien poste mais il manquait le dernier que vous avez ajouté maintenant. je bosse dessus maintenant. :pc:
regardes ce fichier
avec tous les withevents, j'aimerais savoir si ce n'etait pas possible de choisir le nom des deux controls qui nous interressaient? a savoir
Code:
1
2 private withevents txt.msforms.textbox private withevents cmd.msforms.commandbutton
tu veux parler d'un truc comme ça?
Code:
1
2
3
4
5
6
7
8
9
10
11 'Dim Cs() As New TheControl Dim Cs As Object Private Sub UserForm_Initialize() Set Cs = CreateObject("Scripting.Dictionary") For i = 0 To Me.Controls.Count - 1 Cs.Add Controls(i).Name, New TheControl Cs(Controls(i).Name).Objet = Controls(i) Set Cs(Controls(i).Name).Cs = Cs If TypeName(Controls(i)) = "CommandButton" Then Cs(Controls(i).Name).Objet.Enabled = False Next End Sub
Code:
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
49
50
51
52 Private WithEvents Lb As MSForms.Label Private WithEvents Tb As MSForms.TextBox Private WithEvents Cb As MSForms.ComboBox Private WithEvents Ls As MSForms.ListBox Private WithEvents Chb As MSForms.CheckBox Private WithEvents Gb As MSForms.ToggleButton Private WithEvents Fm As MSForms.Frame Private WithEvents Cm As MSForms.CommandButton Private WithEvents Mp As MSForms.MultiPage Private WithEvents Sc As MSForms.ScrollBar Private WithEvents Im As MSForms.Image Private ctrName As String Public Cs As Object Public Property Let Objet(value As Object) ctrName = TypeName(value) Select Case ctrName Case "Label": Set Lb = value Case "TextBox": Set Tb = value Case "ComboBox": Set Cb = value Case "ListBox": Set Ls = value Case "CheckBox": Set Chb = value Case "ToggleButton": Set Gb = value Case "Frame": Set Fm = value Case "CommandButton": Set Cm = value Case "MultiPage": Set Mp = value Case "ScrollBar": Set Sc = value Case "Image": Set Im = value End Select End Property Public Property Get Objet() As Object Select Case ctrName Case "Label": Set Objet = Lb Case "TextBox": Set Objet = Tb Case "ComboBox": Set Objet = Cb Case "ListBox": Set Objet = Ls Case "CheckBox": Set Objet = Chb Case "ToggleButton": Set Objet = Gb Case "Frame": Set Objet = Fm Case "CommandButton": Set Objet = Cm Case "MultiPage": Set Objet = Mp Case "ScrollBar": Set Objet = Sc Case "Image": Set Objet = Im End Select End Property Private Sub Tb_Change() Dim Changer As Boolean If Tb.Name = "TextBox1" Then Cs("CommandButton1").Objet.Enabled = Tb <> "" End If End Sub
genre comme çaCode:
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 Public Property Let Objet(value As Object) ctrName = TypeName(value) Select Case ctrName Case "TextBox": Set Tb = value Case "CommandButton": Set Cm = value End Select End Property Public Property Get Objet() As Object Select Case ctrName Case "TextBox": Set Objet = Tb Case "CommandButton": Set Objet = Cm End Select End Property Private Sub Tb_Change() Dim Changer As Boolean If Trim(Tb.Parent.Name) = "Frame3" Then If Trim(Tb.Parent.Parent.Name) = "Page3" Then For Each txt In Tb.Parent.Controls Debug.Print TypeName(txt) If TypeName(txt) = "TextBox" Then If txt <> "" Then Changer = True: Exit For End If Next For Each cmd In Tb.Parent.Controls If TypeName(cmd) = "CommandButton" Then cmd.Enabled = Changer Next End If End If End Sub
Oui pourquoi pas
mais quand j'ai reduis les private withevents jusqu'au deux controls ça na pas marché. donc si je comprends bien il faut toujours déclarer tous les controls dans les private withevents
je me suis trompé sur la sélection de la suppression. j'avais supprimé private ctr name as string,ce pourquoi ça ne marchait pas. maintenant ça marcheCode:
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 Private WithEvents Tb As MSForms.TextBox Private WithEvents Cm As MSForms.CommandButton Private ctrName As String Public Property Let Objet(value As Object) ctrName = TypeName(value) Select Case ctrName Case "TextBox": Set Tb = value Case "CommandButton": Set Cm = value End Select End Property Public Property Get Objet() As Object Select Case ctrName Case "TextBox": Set Objet = Tb Case "CommandButton": Set Objet = Cm End Select End Property Private Sub Tb_Change() Dim Changer As Boolean If Trim(Tb.Parent.Name) = "Frame3" Then If Trim(Tb.Parent.Parent.Name) = "Page3" Then For Each txt In Tb.Parent.Controls Debug.Print TypeName(txt) If TypeName(txt) = "TextBox" Then If txt <> "" Then Changer = True: Exit For End If Next For Each cmd In Tb.Parent.Controls If TypeName(cmd) = "CommandButton" Then cmd.Enabled = Changer Next End If End If End Sub
tous mes commandbuttons commands sont enabled.je t'envoi le fichier pour voir. les boutons actualiser et supprimer c'est eux je voudrais enabled lorsque les textbox vont etre modifiés. car si je mets textbox<>"" je ne pourrai pas utiliser le bouton supprimer si je pense à supprimer un nom
merci pour ton aide. j'ai trouvé la solution. il suffirait de mettre true au lieu de false dans userform_initialize.merci encore
passez une tres bonne nuit. on se chope demain