Transformation de mon calcul en une fonction
Bonjour,
je veux transformer une partie de mon programme en une fonction car je repéte ce calcul un certaine nombre de fois sauf le nom de certains parametres qui change. dans le programme ci-dessous, je vous indiquerai les parametres qui changent mais le principe du calcul ne change pas.
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| For I = 1 To 17 : il change 3 fois a savoir I = 18 To 35 , I = 36 To 52
Tableau_sans_zero_Q1 , il charge aussi Tableau_sans_zero_Q2, Tableau_sans_zero_Q3
maxLS_Q1 , maxLS_Q2 ,maxLS_Q3
OcQuad_Q1, OcQuad_Q2,OcQuad_Q3
Tableau_cinq_jours_Q1,Tableau_cinq_jours_Q2,Tableau_cinq_jours_Q3
Tableau_moy_lis_Q1,Tableau_moy_lis_Q2,Tableau_moy_lis_Q3
ndim2 = 0
For I = 1 To 17
If tab_som_sem(I) <> 0 Then
ndim2 = ndim2 + 1
End If
Next I
' il definit la nouvelle dim
ReDim Tableau_sans_zero_Q1(ndim2)
ndim_count = 0
For I = 1 To 17
If tab_som_sem(I) <> 0 Then
ndim_count = ndim_count + 1
Tableau_sans_zero_Q1(ndim_count) = tab_som_sem(I)
End If
Next I
If UBound(Tableau_sans_zero_Q1) = 0 Then
MsgBox "Tableau_sans_zero_Q1 est vide"
maxLS_Q1 = 0
OcQuad_Q1 = 0
GoTo quad2
End If
'il fait la moyenne de la production
moy = 0
For I = 1 To ndim2
moy = moy + Tableau_sans_zero_Q1(I)
Next I
moy = moy / ndim2
' compter les semaines en moyenne 5 jrs travaillés
ndim3 = 0
For I = 1 To ndim2
tmp = Tableau_sans_zero_Q1(I) - (moy / 2)
If (tmp > 0) Then
ndim3 = ndim3 + 1
End If
Next I
ReDim Tableau_cinq_jours_Q1(ndim3)
'remplir le tableau avec les elts sup moy/2
ndim_count = 0
For I = 1 To ndim2
tmp = Tableau_sans_zero_Q1(I) - (moy / 2)
If tmp > 0 Then
ndim_count = ndim_count + 1
Tableau_cinq_jours_Q1(ndim_count) = Tableau_sans_zero_Q1(I)
End If
Next I
ReDim Tableau_moy_lis_Q1(ndim3 - 2)
' calcul de toutes les moyennes lissées
For I = 3 To ndim3
Tableau_moy_lis_Q1(I - 2) = (1 / 3) * (Tableau_cinq_jours_Q1(I) + Tableau_cinq_jours_Q1(I - 1) + Tableau_cinq_jours_Q1(I - 2))
Next I
' calcul de la somme du tableau 5 jours travaillés
OcQuad_Q1 = 0
For I = 1 To ndim3
OcQuad_Q1 = OcQuad_Q1 + Tableau_cinq_jours_Q1(I)
Next I
maxLS_Q1 = 0
For I = 1 To (ndim3 - 2)
If Tableau_moy_lis_Q1(I) > maxLS_Q1 Then
maxLS_Q1 = Tableau_moy_lis_Q1(I)
End If
Next I
'MsgBox maxLS_Q1
' y a plus qu'à continuer |