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
| Private Sub CommandButton1_Click() 'bouton "Calculer"
Dim CTRL As Control
Dim B As Integer
Dim I As Byte
For Each CTRL In Me.Controls
Select Case CTRL.Name
Case "matiere", "navire", "num_vte", "client", "mois_vte", "Quantite"
If CTRL.Value = "" Then
MsgBox "Veuillez renseigner le champ : " & Me.Controls("L" & CTRL.Name).Caption & " !"
CTRL.SetFocus
Exit Sub
End If
End Select
Select Case Left(CTRL.Name, 5)
Case "prest"
If CTRL.Value = "" Then
MsgBox "Veuillez choisir la nature de la prestation."
CTRL.SetFocus
Exit Sub
End If
Case "fours"
If CTRL.Value = "" And Me.Controls("prest" & Mid(CTRL.Name, 6)) <> "" Then
MsgBox "Veuillez choisir le fournisseur de la prestation."
CTRL.SetFocus
Exit Sub
End If
Case "m_est"
If CTRL.Value = 0 And Me.Controls("prest" & Mid(CTRL.Name, 6)) <> "" Then
MsgBox "Veuillez saisir le montant estimé."
CTRL.SetFocus
Exit Sub
End If
Case "mnt_r"
If CTRL.Value = "" And Me.Controls("prest" & Mid(CTRL.Name, 6)) <> "" Then
MsgBox "Veuillez saisir le montant réel."
CTRL.SetFocus
Exit Sub
End If
End Select
Select Case Left(CTRL.Name, 3)
Case "fre"
If CTRL.Value = "" And Me.Controls("prest" & Mid(CTRL.Name, 4)) <> "" Then
MsgBox "Veuillez saisir le numéro de la facture."
CTRL.SetFocus
Exit Sub
End If
Case "cpt"
If CTRL.Value = "" And Me.Controls("prest" & Mid(CTRL.Name, 4)) <> "" Then
MsgBox "Veuillez saisir le compte."
CTRL.SetFocus
Exit Sub
End If
End Select
Next CTRL
x = 0
For Each CTRL In Me.Controls
Select Case Left(CTRL.Name, 5)
Case "mnt_r"
x = x = ConvNum(CTRL.Value)
End Select
charges = x
frais_tm = (x * (1 / Quantite))
'Ecart de budget
If matiere = "Fluorure d'Aluminium" Then
B = 10 * Quantite
ecart.Value = charges - B
End If
If matiere = "Anhydrite " Then
B = 8 * Quantite
ecart.Value = charges - B
End If
If matiere = "Spath Fluor" Then
B = 8 * Quantite
ecart.Value = charges - B
End If
If matiere = "Alumine hydratée" Then
B = 8 * Quantite
ecart.Value = charges - B
End If
If matiere = "Alumine calcinée" Then
B = 10 * Quantite
ecart.Value = charges - B
End If
If matiere = "Soufre" Then
B = 12 * Quantite
ecart.Value = charges - B
End If
charges.Value = Format(charges, "#,##0.000")
frais_tm.Value = Format(frais_tm, "#,##0.000")
Quantite.Value = Format(Quantite, "#,##0.000")
For I = 1 To 12
Me.Controls("m_est" & I) = Format(Me.Controls("m_est" & I), "#,##0.000")
Me.Controls("mnt_r" & I) = Format(Me.Controls("mnt_r" & I), "#,##0.000")
Next I
ecart.Value = Format(ecart, "#,##0.000")
mois_vte.Value = Format([mois_vte], "dd/mm/yy")
End Sub
Function ConvNum(n)
If IsNumeric(x) Then
If n <> "" Then
ConvNum = CDbl(n)
Else
ConvNum = 0
End If
Else
ConvNum = 0
End If
End Function |