IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB 6 et antérieur Discussion :

code trop lent


Sujet :

VB 6 et antérieur

  1. #1
    Membre régulier
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2012
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2012
    Messages : 317
    Points : 101
    Points
    101
    Par défaut code trop lent
    Bonjour à tous,
    he bien oui c'est encore moi ; décidément je suis nul
    Cette fois-ci mon code fonctionne mais il est bien trop lent.
    J'ai le flexgrid2 dans lesquels j'inscris les date (il me sert d'entête de colonne, et si la date correspond à un weekend ou un jour férié, je colore les colonnes du flexgrid1 (2 colonne à chaque fois car le tableau est en 1/2 journée)
    le hic c'est qu'il faut au moins 10 bonnes secondes pour effectuer l'oppération et le tableau n'a que 40 lignes, quand je l'aurais agrandi à 200, j'aurais le temps d'aller boire le café

    voici le code

    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
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
     
    Private Sub DTPicker1_Click()
    Dim D As Date, W As String
    Dim h As Integer, m As Integer, J As Integer, fJourFerie, l As Integer, cl As Long
        Dim tmpDate
     
     
    MSFlexGrid2.Row = 0
    MSFlexGrid2.Col = 3
    D = Me.DTPicker1
     
    MSFlexGrid2.Text = Format$(Me.DTPicker1 - 1, "dd/mm/yy")
     
    Dim A As Long, B As Long
    A = 4
    For A = 4 To 52
    If A > 4 Then
    cl = A - 4 + A
    Else
    cl = 4
    End If
     
    'incrémentation de la date
     
    'adresse de la date
    MSFlexGrid2.Row = 0
    MSFlexGrid2.Col = A
    'extraction du jour (lettre)
    W = WeekdayName(Weekday(D))
    'extraction de l'année, du mois et du jour (nombre)
    h = Year(D): m = Month(D): J = Day(D)
    'calcul du lundi de pâque
     tmpDate = fLundiPaques(h)
    'si l'on est un samedi ou un dimanche je colore en jaune les entêtes et les colonnes du tableau
    If W = "samedi" Or W = "dimanche" Then
    MSFlexGrid2.CellBackColor = &HFFFF&
    'j'inscrit samedi ou dimanche en entête
    MSFlexGrid2.Text = Format$(W, "dd/mm/yy")
    'coloriage du tableau
    B = cl
    For l = 1 To 39
     
    MSFlexGrid1.Row = l
    MSFlexGrid1.Col = B
    MSFlexGrid1.CellBackColor = &HFFFF&
     
    If l = 39 And B = cl Then
    l = 0
    B = B + 1
    End If
     
    Next l
     
     
    '1er janvier
    ElseIf m = 1 And J = 1 Then
    MSFlexGrid2.CellBackColor = &HFFFF&
    MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
    For l = 1 To 39
     
    MSFlexGrid1.Row = l
    MSFlexGrid1.Col = B
    MSFlexGrid1.CellBackColor = &HFFFF&
    If l = 39 And B = cl Then
    l = 0
    B = B + 1
    End If
    Next l
    '1ermai
    ElseIf m = 5 And J = 1 Then
    MSFlexGrid2.CellBackColor = &HFFFF&
    MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
    For l = 1 To 39
     
    MSFlexGrid1.Row = l
    MSFlexGrid1.Col = B
    MSFlexGrid1.CellBackColor = &HFFFF&
    If l = 39 And B = cl Then
    l = 0
    B = B + 1
    End If
    Next l
    '8 mai
    ElseIf m = 5 And J = 8 Then
    MSFlexGrid2.CellBackColor = &HFFFF&
    MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
    For l = 1 To 39
     
    MSFlexGrid1.Row = l
    MSFlexGrid1.Col = B
    MSFlexGrid1.CellBackColor = &HFFFF&
    If l = 39 And B = cl Then
    l = 0
    B = B + 1
    End If
    Next l
    '14 juillet
    ElseIf m = 7 And J = 14 Then
    MSFlexGrid2.CellBackColor = &HFFFF&
    MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
    For l = 1 To 39
     
    MSFlexGrid1.Row = l
    MSFlexGrid1.Col = B
    MSFlexGrid1.CellBackColor = &HFFFF&
    If l = 39 And B = cl Then
    l = 0
    B = B + 1
    End If
    Next l
    '15 aout
    ElseIf m = 8 And J = 15 Then
    MSFlexGrid2.CellBackColor = &HFFFF&
    MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
    For l = 1 To 39
     
    MSFlexGrid1.Row = l
    MSFlexGrid1.Col = B
    MSFlexGrid1.CellBackColor = &HFFFF&
    If l = 39 And B = cl Then
    l = 0
    B = B + 1
    End If
    Next l
    'tousaint
    ElseIf m = 11 And J = 1 Then
    MSFlexGrid2.CellBackColor = &HFFFF&
    MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
    For l = 1 To 39
     
    MSFlexGrid1.Row = l
    MSFlexGrid1.Col = B
    MSFlexGrid1.CellBackColor = &HFFFF&
    If l = 39 And B = cl Then
    l = 0
    B = B + 1
    End If
    Next l
    '11 novembre
    ElseIf m = 11 And J = 11 Then
    MSFlexGrid2.CellBackColor = &HFFFF&
    MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
    For l = 1 To 39
     
    MSFlexGrid1.Row = l
    MSFlexGrid1.Col = B
    MSFlexGrid1.CellBackColor = &HFFFF&
    If l = 39 And B = cl Then
    l = 0
    B = B + 1
    End If
    Next l
    'noel
    ElseIf m = 12 And J = 25 Then
    MSFlexGrid2.CellBackColor = &HFFFF&
    MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
    For l = 1 To 39
     
    MSFlexGrid1.Row = l
    MSFlexGrid1.Col = B
    MSFlexGrid1.CellBackColor = &HFFFF&
    If l = 39 And B = cl Then
    l = 0
    B = B + 1
    End If
    Next l
     
     
    ElseIf D = tmpDate Then
     
    MSFlexGrid2.CellBackColor = &HFFFF&
    MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
    For l = 1 To 39
     
    MSFlexGrid1.Row = l
    MSFlexGrid1.Col = B
    MSFlexGrid1.CellBackColor = &HFFFF&
    If l = 39 And B = cl Then
    l = 0
    B = B + 1
    End If
     
    Next l
    Else
    MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
     
    End If
    D = D + 1
    Fin = Format$(D, "dd/mm/yy")
    Next A
    End Sub
    bien sur c'est du boulot d'amateur, mais au lieu de faire une boucle, s'il y avait moyen de sélectionner la plage de cellule, je pense que ça accélérerait le processus. Mais je n'ai pas trouvé comment faire...

    merci pour votre aide


    cordialement

  2. #2
    Membre éclairé
    Inscrit en
    Décembre 2007
    Messages
    512
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 512
    Points : 671
    Points
    671
    Par défaut
    Bonjour,

    Une remarque apprend à coder en retrait pour rendre ton code plus lisible
    Exemple ci-dessous
    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
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
     
     
    Private Sub DTPicker1_Click()
    Dim D As Date, W As String
    Dim h As Integer, m As Integer, J As Integer, fJourFerie, l As Integer, cl As Long
        Dim tmpDate
     
     
    MSFlexGrid2.Row = 0
    MSFlexGrid2.Col = 3
    D = Me.DTPicker1
     
    MSFlexGrid2.Text = Format$(Me.DTPicker1 - 1, "dd/mm/yy")
     
    Dim A As Long, B As Long
    A = 4
    For A = 4 To 52
       If A > 4 Then
           cl = A - 4 + A
                Else
           cl = 4
       End If
     
       'incrémentation de la date
     
       'adresse de la date
       MSFlexGrid2.Row = 0
       MSFlexGrid2.Col = A
       'extraction du jour (lettre)
       W = WeekdayName(Weekday(D))
       'extraction de l'année, du mois et du jour (nombre)
       h = Year(D): m = Month(D): J = Day(D)
       'calcul du lundi de pâque
       tmpDate = fLundiPaques(h)
       'si l'on est un samedi ou un dimanche je colore en jaune les entêtes et les colonnes du tableau
       If W = "samedi" Or W = "dimanche" Then
                    MSFlexGrid2.CellBackColor = &HFFFF&
                    'j'inscrit samedi ou dimanche en entête
                    MSFlexGrid2.Text = Format$(W, "dd/mm/yy")
                    'coloriage du tableau
                    B = cl
                    For l = 1 To 39
     
                      MSFlexGrid1.Row = l
                      MSFlexGrid1.Col = B
                      MSFlexGrid1.CellBackColor = &HFFFF&
     
                      If l = 39 And B = cl Then
                              l = 0
                              B = B + 1
                      End If
     
                    Next l
     
     
                   '1er janvier
                 ElseIf m = 1 And J = 1 Then
                   MSFlexGrid2.CellBackColor = &HFFFF&
                   MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                   For l = 1 To 39
     
                      MSFlexGrid1.Row = l
                      MSFlexGrid1.Col = B
                      MSFlexGrid1.CellBackColor = &HFFFF&
                      If l = 39 And B = cl Then
                               l = 0
                               B = B + 1
                      End If
                   Next l
                   '1ermai
                 ElseIf m = 5 And J = 1 Then
                      MSFlexGrid2.CellBackColor = &HFFFF&
                      MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                      For l = 1 To 39
     
                        MSFlexGrid1.Row = l
                        MSFlexGrid1.Col = B
                        MSFlexGrid1.CellBackColor = &HFFFF&
                        If l = 39 And B = cl Then
                              l = 0
                              B = B + 1
                        End If
                      Next l
                      '8 mai
                  ElseIf m = 5 And J = 8 Then
                     MSFlexGrid2.CellBackColor = &HFFFF&
                     MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                     For l = 1 To 39
     
                       MSFlexGrid1.Row = l
                       MSFlexGrid1.Col = B
                       MSFlexGrid1.CellBackColor = &HFFFF&
                       If l = 39 And B = cl Then
                             l = 0
                             B = B + 1
                       End If
                     Next l
                     '14 juillet
                  ElseIf m = 7 And J = 14 Then
                       MSFlexGrid2.CellBackColor = &HFFFF&
                       MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                       For l = 1 To 39
     
                          MSFlexGrid1.Row = l
                          MSFlexGrid1.Col = B
                          MSFlexGrid1.CellBackColor = &HFFFF&
                          If l = 39 And B = cl Then
                                 l = 0
                                 B = B + 1
                          End If
                       Next l
                       '15 aout
                  ElseIf m = 8 And J = 15 Then
                       MSFlexGrid2.CellBackColor = &HFFFF&
                       MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                       For l = 1 To 39
     
                         MSFlexGrid1.Row = l
                         MSFlexGrid1.Col = B
                         MSFlexGrid1.CellBackColor = &HFFFF&
                         If l = 39 And B = cl Then
                              l = 0
                              B = B + 1
                         End If
                       Next l
                       'tousaint
                  ElseIf m = 11 And J = 1 Then
                       MSFlexGrid2.CellBackColor = &HFFFF&
                       MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                       For l = 1 To 39
     
                         MSFlexGrid1.Row = l
                         MSFlexGrid1.Col = B
                         MSFlexGrid1.CellBackColor = &HFFFF&
                         If l = 39 And B = cl Then
                              l = 0
                              B = B + 1
                         End If
                      Next l
                      '11 novembre
                 ElseIf m = 11 And J = 11 Then
                      MSFlexGrid2.CellBackColor = &HFFFF&
                      MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                      For l = 1 To 39
     
                        MSFlexGrid1.Row = l
                        MSFlexGrid1.Col = B
                        MSFlexGrid1.CellBackColor = &HFFFF&
                        If l = 39 And B = cl Then
                             l = 0
                             B = B + 1
                        End If
                      Next l
                      'noel
                 ElseIf m = 12 And J = 25 Then
                      MSFlexGrid2.CellBackColor = &HFFFF&
                      MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                      For l = 1 To 39
     
                        MSFlexGrid1.Row = l
                        MSFlexGrid1.Col = B
                        MSFlexGrid1.CellBackColor = &HFFFF&
                        If l = 39 And B = cl Then
                             l = 0
                             B = B + 1
                        End If
                      Next l
     
     
                ElseIf D = tmpDate Then
     
                      MSFlexGrid2.CellBackColor = &HFFFF&
                      MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                      For l = 1 To 39
     
                        MSFlexGrid1.Row = l
                        MSFlexGrid1.Col = B
                        MSFlexGrid1.CellBackColor = &HFFFF&
                        If l = 39 And B = cl Then
                             l = 0
                             B = B + 1
                        End If
     
                      Next l
                Else
                      MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
     
       End If
       D = D + 1
       Fin = Format$(D, "dd/mm/yy")
    Next A
    End Sub

  3. #3
    Membre éclairé
    Inscrit en
    Décembre 2007
    Messages
    512
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 512
    Points : 671
    Points
    671
    Par défaut
    ... et remplacer tes 'elseif par un 'select case beaucoup plus performant
    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
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
     
     
    Private Sub DTPicker1_Click()
    Dim D As Date, W As String
    Dim h As Integer, m As Integer, j As Integer, fJourFerie, l As Integer, cl As Long
        Dim tmpDate
     
     
    MSFlexGrid2.Row = 0
    MSFlexGrid2.Col = 3
    D = Me.DTPicker1
     
    MSFlexGrid2.Text = Format$(Me.DTPicker1 - 1, "dd/mm/yy")
     
    Dim A As Long, B As Long
    A = 4
    For A = 4 To 52
       If A > 4 Then
           cl = A - 4 + A
                Else
           cl = 4
       End If
     
       'incrémentation de la date
     
       'adresse de la date
       MSFlexGrid2.Row = 0
       MSFlexGrid2.Col = A
       'extraction du jour (lettre)
       W = WeekdayName(Weekday(D))
       'extraction de l'année, du mois et du jour (nombre)
       h = Year(D): m = Month(D): j = Day(D)
       'calcul du lundi de pâque
       tmpDate = fLundiPaques(h)
       'si l'on est un samedi ou un dimanche je colore en jaune les entêtes et les colonnes du tableau
       If W = "samedi" Or W = "dimanche" Then
                    MSFlexGrid2.CellBackColor = &HFFFF&
                    'j'inscrit samedi ou dimanche en entête
                    MSFlexGrid2.Text = Format$(W, "dd/mm/yy")
                    'coloriage du tableau
                    B = cl
                    For l = 1 To 39
     
                      MSFlexGrid1.Row = l
                      MSFlexGrid1.Col = B
                      MSFlexGrid1.CellBackColor = &HFFFF&
     
                      If l = 39 And B = cl Then
                              l = 0
                              B = B + 1
                      End If
     
                    Next l
        End If
     
        Select Case m And j
                   '1er janvier
             Case m = 1 And j = 1
                   MSFlexGrid2.CellBackColor = &HFFFF&
                   MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                   For l = 1 To 39
     
                      MSFlexGrid1.Row = l
                      MSFlexGrid1.Col = B
                      MSFlexGrid1.CellBackColor = &HFFFF&
                      If l = 39 And B = cl Then
                               l = 0
                               B = B + 1
                      End If
                   Next l
                   '1ermai
              Case m = 5 And j = 1
                      MSFlexGrid2.CellBackColor = &HFFFF&
                      MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                      For l = 1 To 39
     
                        MSFlexGrid1.Row = l
                        MSFlexGrid1.Col = B
                        MSFlexGrid1.CellBackColor = &HFFFF&
                        If l = 39 And B = cl Then
                              l = 0
                              B = B + 1
                        End If
                      Next l
                      '8 mai
               Case m = 5 And j = 8
                     MSFlexGrid2.CellBackColor = &HFFFF&
                     MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                     For l = 1 To 39
     
                       MSFlexGrid1.Row = l
                       MSFlexGrid1.Col = B
                       MSFlexGrid1.CellBackColor = &HFFFF&
                       If l = 39 And B = cl Then
                             l = 0
                             B = B + 1
                       End If
                     Next l
                     '14 juillet
               Case m = 7 And j = 14
                       MSFlexGrid2.CellBackColor = &HFFFF&
                       MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                       For l = 1 To 39
     
                          MSFlexGrid1.Row = l
                          MSFlexGrid1.Col = B
                          MSFlexGrid1.CellBackColor = &HFFFF&
                          If l = 39 And B = cl Then
                                 l = 0
                                 B = B + 1
                          End If
                       Next l
                       '15 aout
              Case m = 8 And j = 15
                       MSFlexGrid2.CellBackColor = &HFFFF&
                       MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                       For l = 1 To 39
     
                         MSFlexGrid1.Row = l
                         MSFlexGrid1.Col = B
                         MSFlexGrid1.CellBackColor = &HFFFF&
                         If l = 39 And B = cl Then
                              l = 0
                              B = B + 1
                         End If
                       Next l
                       'tousaint
              Case m = 11 And j = 1
                       MSFlexGrid2.CellBackColor = &HFFFF&
                       MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                       For l = 1 To 39
     
                         MSFlexGrid1.Row = l
                         MSFlexGrid1.Col = B
                         MSFlexGrid1.CellBackColor = &HFFFF&
                         If l = 39 And B = cl Then
                              l = 0
                              B = B + 1
                         End If
                      Next l
                      '11 novembre
              Case m = 11 And j = 11
                      MSFlexGrid2.CellBackColor = &HFFFF&
                      MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                      For l = 1 To 39
     
                        MSFlexGrid1.Row = l
                        MSFlexGrid1.Col = B
                        MSFlexGrid1.CellBackColor = &HFFFF&
                        If l = 39 And B = cl Then
                             l = 0
                             B = B + 1
                        End If
                      Next l
                      'noel
              Case m = 12 And j = 25
                      MSFlexGrid2.CellBackColor = &HFFFF&
                      MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                      For l = 1 To 39
     
                        MSFlexGrid1.Row = l
                        MSFlexGrid1.Col = B
                        MSFlexGrid1.CellBackColor = &HFFFF&
                        If l = 39 And B = cl Then
                             l = 0
                             B = B + 1
                        End If
                      Next l
     
     
               Case Else
                   If D = tmpDate Then
     
                      MSFlexGrid2.CellBackColor = &HFFFF&
                      MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
                      For l = 1 To 39
     
                        MSFlexGrid1.Row = l
                        MSFlexGrid1.Col = B
                        MSFlexGrid1.CellBackColor = &HFFFF&
                        If l = 39 And B = cl Then
                             l = 0
                             B = B + 1
                        End If
     
                      Next l
                                  Else
                      MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
     
                    End If
       End Select
       D = D + 1
       Fin = Format$(D, "dd/mm/yy")
    Next A
    End Sub

  4. #4
    Membre régulier
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2012
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2012
    Messages : 317
    Points : 101
    Points
    101
    Par défaut
    je ne maitrise pas bien les select case et comme je ne vois pas ce que ça fait de plus que des if, je ne les utilises jamais. J'ai essayé ton code mais pas de différence de rapidité, du moins en apparence.
    J'ai déjà fais le même tableau en VBA dans excel et il est tellement lent qu'il en devient inutilisable. J'espérais qu'avec VB6 j'arriverais à contourner le problème, mais les boucles sont tout aussi lentes qu'en vba ; pourtant le code n'est pas si long que ça 6 ou 7 ligne pour une boucle. Dans mon programme excel j'ai des boucles de 50 lignes donc la lenteur se comprend
    enfin je vois que j'ai encore beaucoup à apprendre et que c'est pas gagné même si j'arrive parfois à réaliser tout seul un code qui tourne....

    merci iclic pour ta réponse

  5. #5
    Membre éclairé
    Inscrit en
    Décembre 2007
    Messages
    512
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 512
    Points : 671
    Points
    671
    Par défaut
    Bonsoir,

    A voir ton code et à vérifier
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
     For l = 1 To 39
     
                       MSFlexGrid1.Row = l
                       MSFlexGrid1.Col = B
                       MSFlexGrid1.CellBackColor = &HFFFF&
                       If l = 39 And B = cl Then
                             l = 0
                             B = B + 1
                       End If
      Next l
    Donc si tu tombes dans la condition ' If l = 39 And B = cl Then
    l = 0 ... et tu recommences ta boucle... et si celà arrive plusieurs fois,
    est-ce que ça peut expliquer la lenteur,

  6. #6
    Modérateur
    Avatar de ProgElecT
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2004
    Messages
    6 077
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Décembre 2004
    Messages : 6 077
    Points : 17 176
    Points
    17 176
    Par défaut
    Salut

    A iclic
    Select Case m And j ..... Case m = 1 And j = 1 ne provoque pas d'erreur mais ne fonctionne pas (dommage )

    A dmoluc
    La colorisation cellule par cellule est toujours longue, essais plutôt de paramétrer une plage de cellules.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    'MSFlexGrid1.FillStyle = flexFillRepeat ' Proriété à faire en design
    'colorisation d'une plage de celulle
    MSFlexGrid1.Row = 2: MSFlexGrid1.Col = 1 'ligne et colonne de départ
    MSFlexGrid1.RowSel = 4: MSFlexGrid1.ColSel = 3 'ligne et colonne de fin
    MSFlexGrid1.CellBackColor = vbRed 'application de la couleur
    A prendre en compte, la cellule en cour (Row,Col) affiche les couleurs encre et fond (ForeColorSel et BackColorSel), ce qui masque durant ce temps les couleurs CellBackColor et CellForeColor.
    Soyez sympa, pensez -y
    Balises[CODE]...[/CODE]
    Balises[CODE=NomDuLangage]...[/CODE] quand vous mettez du code d'un autre langage que celui du forum ou vous postez.
    Balises[C]...[/C] code intégré dans une phrase.
    Balises[C=NomDuLangage]...[/C] code intégré dans une phrase quand vous mettez du code d'un autre langage que celui du forum ou vous postez.
    Le bouton en fin de discussion, quand vous avez obtenu l'aide attendue.
    ......... et pourquoi pas, pour remercier, un pour celui/ceux qui vous ont dépannés.
    👉 → → Ma page perso sur DVP ← ← 👈

  7. #7
    Membre éclairé
    Inscrit en
    Décembre 2007
    Messages
    512
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 512
    Points : 671
    Points
    671
    Par défaut
    Bonjour,

    A Progelec

    Exact , mais on peut faire alors...
    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
     
    Dim ferie As String
     
    Ferie = Trim(Str(m)) & Trim(Str(j))
     
    Select Case Ferie
     
        Case "11"
          '...
        Case "51"
          '...
        Case "58"
          '...
        Case "714"
         '...
        Case "815"
          '...
        Case "111"
          '...
        Case "1111"
          '...
        Case "1225"
          '...
        Case Else
         '...
     
    End Select
    Et là cela fonctionne parfaitement

  8. #8
    Membre régulier
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2012
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2012
    Messages : 317
    Points : 101
    Points
    101
    Par défaut
    Bonjour

    Merci progelec, c'est exactement ce que je cherchais à faire sans en connaitre la syntaxe, et merci aussi à iclic pour m'en avoir apris un peu plus sur les select cases. J'avais lu quelque part que les select cases n'apportaient pas grand chose par rapport aux if, alors je n'avais vraiment pas étudier la question....
    C'est malheureux je suis en vacance et je n'arrive pas à m'occuper autre chose que de ce code Mes chiens vont finir par me mordre si je ne les emmènes pas un peu dans les bois
    encore merci à tous les deux, j'essais de faire fonctionner le code et je vous tien au courant

  9. #9
    Membre régulier
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2012
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2012
    Messages : 317
    Points : 101
    Points
    101
    Par défaut
    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
     
    MSFlexGrid2.Row = 0
    MSFlexGrid2.Col = A
    'extraction du jour (lettre)
    W = WeekdayName(Weekday(D))
    'extraction de l'année, du mois et du jour (nombre)
    h = Year(D): m = Month(D): J = Day(D)
    'calcul du lundi de pâque
     tmpDate = fLundiPaques(h)
    'si l'on est un samedi ou un dimanche je colore en jaune les entêtes et les colonnes du tableau
     
    If W = "samedi" Or W = "dimanche" Then
    MSFlexGrid2.CellBackColor = &HFFFF&
    'j'inscrit samedi ou dimanche en entête
    MSFlexGrid2.Text = Format$(W, "dd/mm/yy")
    'coloriage du tableau
    'colorisation d'une plage de celulle
    MSFlexGrid1.Row = 0: MSFlexGrid1.Col = A 'ligne et colonne de départ
    MSFlexGrid1.RowSel = MSFlexGrid1.Rows - 1: MSFlexGrid1.ColSel = A + 1  'ligne et colonne de fin
    MSFlexGrid1.CellBackColor = &HFFFF&
     
    '1er janvier
    ElseIf m = 1 And J = 1 Then
    MSFlexGrid2.CellBackColor = &HFFFF&
    MSFlexGrid2.Text = Format$(D, "dd/mm/yy")
    MSFlexGrid1.Row = 0: MSFlexGrid1.Col = A 'ligne et colonne de départ
    MSFlexGrid1.RowSel = MSFlexGrid1.Rows - 1: MSFlexGrid1.ColSel = A + 1  'ligne et colonne de fin
    MSFlexGrid1.CellBackColor = &HFFFF&
     
    'etc....
    Voilà un extrait du code qui fonctionne à merveille, bien sur il pourrait s'améliorré car j'utilise la même instruction pour chaque jour férié : quand je saurais faire les fonctions je reprendrais ça
    Je n'ai pas encore essayé les select cases mais je vais tenter l'expérience sinon je ne m'y mettrais jamais

    Merci à tous les deux

    A +

  10. #10
    Membre régulier
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2012
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2012
    Messages : 317
    Points : 101
    Points
    101
    Par défaut
    Encore une petite question : comment faut-il faire pour déplacer le flexgrid2 et le flexgrid1 avec la même scroolbar horizontal
    j'ai supprimer celle du flexgrid 2 qui sert d'entête, alors ça serait bien qu'il soit "soudé" à celui de dessous, ci c'est possible bien sur

    merci d'avance

  11. #11
    Membre éclairé
    Inscrit en
    Décembre 2007
    Messages
    512
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 512
    Points : 671
    Points
    671
    Par défaut
    Bonjour,

    Attention dmoluc

    Petite modification pour l'emploi du 'select case
    pour éviter les doublons (1er janvier et 11 janvier par exemple)
    ferait "111" à chaque fois.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    '...
    ferie = Right("00" & Trim(Str(m)), 2) & Right("00" & Trim(Str(j)), 2)
    Select Case ferie
     
        Case "0101"  ' 1er janvier <> 11 janvier "0111"
         '...
        Case "0501"
           '...
        Case "0508"
           '...

  12. #12
    Membre régulier
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2012
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2012
    Messages : 317
    Points : 101
    Points
    101
    Par défaut
    ok merci par contre j'ai oublié le jeudi de l’ascension et je ne sais pas comment le calculer sinon le code fonctionne impeccable, le tableau ce colore à la vitesse de la lumière
    il va falloir que je regarde le code vba du programme que j'ai fait avec excel, si j'arrive à traduire ce code, mon tableau va peu être être utilisable... mais bon je pense qu'un programme créer avec vb6 posera moins de problème qu'un classeur excel en VBA car par exemple les DTPicker ne sont pas les même entre XP et windows 7, les fonctions 32 bits ne fonctionne pas en 64 bits Etc...
    Alors j'espère que grace au select cases et autres petits truc je vais arrivé à créer quelque chose d'utilisable

    A +

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Code trop lent pour une écriture sur disque
    Par Anarchy64 dans le forum C
    Réponses: 6
    Dernier message: 12/12/2013, 19h54
  2. Optimisation code trop lent
    Par Pynouz dans le forum Windows Forms
    Réponses: 3
    Dernier message: 27/02/2013, 14h44
  3. Code trop lent à optimiser
    Par deuche dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 12/10/2011, 16h18
  4. Code trop lent: recuperation de donnees dans un autre classeur
    Par nianko dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 05/01/2010, 10h43
  5. [Eclipse] Editeur de code trop lent
    Par Benzeghiba dans le forum Eclipse Java
    Réponses: 6
    Dernier message: 10/11/2005, 14h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo