Bonjour a toutes et tous, Forum

Je souhaiterai svp optimiser un code voir ci-dessous car je rencontre des lenteurs de chargement du programme de ma gestion vidéo.

Je ne vois pas comment faire autrement que de répèter 27 fois le code Label 100 à 126

Merci a vous pour votre temps et merci d'avoir lu ma demande, bonne journée

PS: le programme fonctionne très bien juste un peu long a se charger.
PS: mis juste procédures pour exemple sinon ça fait 567 lignes de code

Cordialement Ray

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 
'* LES 27 PROCEDURES SUIVANTES PERMETTENT DE DETECTER QUAND LA SOURIS SURVOLE LE LABEL
'* EN CAS DE SURVOL, LA CASE DEVIENT ROUGE ET LA CASE EN-DESSOUS DEVIENT JAUNE
Private Sub Label100_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
  For i = 100 To 126
    With Me
      If .Controls("Label" & i).Name = "Label100" Then
        .Controls("Label" & i).BackColor = RGB(255, 0, 0)    'Rouge
        .Controls("Label" & i + 27).BackColor = &HFFFF80     'Turquoise
        If .Controls("Label" & i + 27).Caption <> "" Then
          Gestion_du_listing.TextBox3.Value = .Controls("Label" & i).Caption & " : " & .Controls("Label" & i + 27).Caption
        Else
          Gestion_du_listing.TextBox3.Value = ""
        End If
      Else
        If .Controls("Label" & i).BackColor <> &H800080 And _
           .Controls("Label" & i + 27).BackColor <> &HC0C0FF Then
          .Controls("Label" & i).BackColor = &H800080          'Violet
          .Controls("Label" & i + 27).BackColor = &HC0C0FF     'Rose
        End If
      End If
    End With
  Next i
End Sub
 
Private Sub Label101_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
  For i = 100 To 126
    With Me
      If .Controls("Label" & i).Name = "Label101" Then
        .Controls("Label" & i).BackColor = RGB(255, 0, 0)
        .Controls("Label" & i + 27).BackColor = &HFFFF80
        If .Controls("Label" & i + 27).Caption <> "" Then
          Gestion_du_listing.TextBox3.Value = .Controls("Label" & i).Caption & " : " & .Controls("Label" & i + 27).Caption
        Else
          Gestion_du_listing.TextBox3.Value = ""
        End If
      Else
        If .Controls("Label" & i).BackColor <> &H800080 And _
           .Controls("Label" & i + 27).BackColor <> &HC0C0FF Then
          .Controls("Label" & i).BackColor = &H800080
          .Controls("Label" & i + 27).BackColor = &HC0C0FF
        End If
      End If
    End With
  Next i
End Sub
 
Private Sub Label102_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
  For i = 100 To 126
    With Me
      If .Controls("Label" & i).Name = "Label102" Then
        .Controls("Label" & i).BackColor = RGB(255, 0, 0)
        .Controls("Label" & i + 27).BackColor = &HFFFF80
        If .Controls("Label" & i + 27).Caption <> "" Then
          Gestion_du_listing.TextBox3.Value = .Controls("Label" & i).Caption & " : " & .Controls("Label" & i + 27).Caption
        Else
          Gestion_du_listing.TextBox3.Value = ""
        End If
      Else
        If .Controls("Label" & i).BackColor <> &H800080 And _
           .Controls("Label" & i + 27).BackColor <> &HC0C0FF Then
          .Controls("Label" & i).BackColor = &H800080
          .Controls("Label" & i + 27).BackColor = &HC0C0FF
        End If
      End If
    End With
  Next i
End Sub
 
Private Sub Label103_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
  For i = 100 To 126
    With Me
      If .Controls("Label" & i).Name = "Label103" Then
        .Controls("Label" & i).BackColor = RGB(255, 0, 0)
        .Controls("Label" & i + 27).BackColor = &HFFFF80
        If .Controls("Label" & i + 27).Caption <> "" Then
          Gestion_du_listing.TextBox3.Value = .Controls("Label" & i).Caption & " : " & .Controls("Label" & i + 27).Caption
        Else
          Gestion_du_listing.TextBox3.Value = ""
        End If
      Else
        If .Controls("Label" & i).BackColor <> &H800080 And _
           .Controls("Label" & i + 27).BackColor <> &HC0C0FF Then
          .Controls("Label" & i).BackColor = &H800080
          .Controls("Label" & i + 27).BackColor = &HC0C0FF
        End If
      End If
    End With
  Next i
End Sub