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
| Option Explicit
Private debits, dispo, dispo1, restes
Private Sub Command1_Click()
If Not verifions Then
MsgBox "une donnée est manquante !"
Exit Sub
End If
Dim rep As Double, arep As Double, arep1 As Double, i As Integer, combien As Double, distribues As String
arep = Val(commande.Text)
arep1 = CDbl(arep)
distribues = ""
For i = 0 To UBound(debits)
combien = Int(CDbl(arep1) / CDbl(Val(debits(i))))
If combien > dispo(i) Then combien = dispo(i)
dispo(i) = dispo(i) - combien
arep1 = arep1 - (combien * CDbl(debits(i)))
rep = rep + (combien * CDbl(debits(i)))
If combien > 0 Then distribues = distribues & combien & " * " & debits(i) & vbCrLf
Next
If arep > rep Then
Dim avoir As Double
For i = 0 To UBound(debits)
avoir = avoir + (dispo(i) * debits(i))
Next
If avoir > (arep - rep) Then
MsgBox " pas de quoi faire appoint "
Else
MsgBox " pas assez dans les cuves et vous devriez encore " & arep - rep & " litres" & vbCrLf & _
"vous ne pourriez en effet distribuer que ceci :" & vbCrLf & distribues
End If
distribues = ""
Let dispo = dispo1
Else
MsgBox "vous avez distribué " & distribues
Let dispo1 = dispo
citerne1.Text = dispo1(0) * debits(0) + restes(0): citerne2.Text = dispo1(1) * debits(1): citerne3.Text = dispo1(2) * debits(2)
End If
End Sub
Private Function verifions() As Boolean
verifions = False
If Not IsNumeric(citerne1) Then Exit Function
If Not IsNumeric(citerne2) Then Exit Function
If Not IsNumeric(citerne2) Then Exit Function
If Not IsNumeric(debit1) Then Exit Function
If Not IsNumeric(debit2) Then Exit Function
If Not IsNumeric(debit3) Then Exit Function
If Not IsNumeric(commande) Then Exit Function
debits = Array(Val(debit1), Val(debit2), Val(debit3))
dispo = Array(Val(citerne1.Text) \ debits(0), Val(citerne2.Text) \ debits(1), Val(citerne3.Text) \ debits(2))
restes = Array(Val(citerne1) Mod debits(0), Val(citerne2) Mod debits(1), Val(citerne3) Mod debits(2))
verifions = True
End Function |
Partager