Pouvez-vous me donner quelques conseilles et exemples

cs_Sipat Messages postés 71 Date d'inscription mardi 26 octobre 2004 Statut Membre Dernière intervention 15 avril 2007 - 20 févr. 2005 à 11:26
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 - 20 févr. 2005 à 12:15
Bon dimanche à tous,
j'aimerai pouvoir saisir dans les différents textbox en temps réel
J'y suis arrivé avec TextBox1(PAHT) TextBox2(PVHT) TextBox4(PVTTC)
mais je n'arrive pas avec TextBox3(TM) et TextBox5(COEF)


Voici mon code pouvez-vous de donner des conseilles svp ?
Merci.


Public TVA As Double


Private Sub TEXT5_Change()
'COEFFICIENT
' COEF = PVTTC / PAHT
On Error GoTo fin
Text5.Text = Round(Text5.Text, 3)
fin:
End Sub


Private Sub Command1_Click()
' EFFACER
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
End Sub


Private Sub Command2_Click()
'FERMER
Unload Form1
End Sub


Private Sub Form_Load()
TVA = 1.055
End Sub


Private Sub Option1_Click()
'TVA
On Error GoTo SUITE
'TVA 5.5 % Option1
If Option1.Value = True Then
Option2.Value = False
'Option1.SetFocus
TVA = 1.055
Text4.Text = Round((Text2.Text * TVA), 3)


End If
Text6.Text = Text4.Text - Text2.Text
Text8.Text = ((Text2.Text - Text1.Text) / Text4.Text * 100)
Text5.Text = Text4.Text / Text1.Text
SUITE:
End Sub


Private Sub Option2_Click()
'TVA
On Error GoTo fin
'TVA 19,6 % Option2
If Option2.Value = True Then
Option1.Value = False
' Option2.SetFocus
TVA = 1.196
Text4.Text = Round((Text2.Text * TVA), 3)

End If

Text6.Text = Text4.Text - Text2.Text
Text8.Text = ((Text2.Text - Text1.Text) / Text4.Text * 100)
Text5.Text = Text4.Text / Text1.Text
fin:
End Sub


Private Sub Text1_Change()
'PAHTIf Text1.Text "" Then Text3.Text "": Text7.Text = "":


Text8.Text "": Text5.Text ""
If Len(Text1.Text) < 1 Then Exit Sub
Text1.Text = Trim(Text1.Text) 'enleve les espaces droite et gaucheIf Mid(Text1.Text, 1, 1) "," Then Text1.Text ""
End Sub


Private Sub TEXT1_KeyPress(KeyAscii As Integer)
'8 = TOUCHE RET ARR ; 46 TOUCHE POINT DECIMAL ;44 TOUCHE VIRGULE
If KeyAscii <> 8 And (KeyAscii < 48 Or KeyAscii > 57) Then
If KeyAscii = 44 Then
If InStr(1, Text1.Text, ",") Then KeyAscii = 0
ElseIf KeyAscii = 46 Then
If InStr(1, Text1.Text, ",") Then
KeyAscii = 0
Else
KeyAscii = 44
End If
Else
KeyAscii = 0
End If
End If
End Sub
Private Sub TEXT1_KeyUp(KeyCode As Integer, Shift As Integer)
'PAHT
On Error GoTo fin
Text3.Text = ((Text2.Text - Text1.Text) / Text2.Text * 100)
Text8.Text = ((Text2.Text - Text1.Text) / Text4.Text * 100)
Text7.Text = Text2.Text - Text1.Text
Text5.Text = Text4.Text / Text1.Text


fin:
End Sub


Private Sub TEXT2_Change()
'PVHT
'PVHT = PVTTC / ( ( TVA + 100 ) / 100 )If Text2.Text "" Then Text4.Text "": Text3.Text = "":


Text6.Text "": Text7.Text "": Text8.Text = "": Text5.Text = ""
If Len(Text2.Text) < 1 Then Exit Sub
Text2.Text = Trim(Text2.Text) 'enleve les espaces droite et gaucheIf Mid(Text2.Text, 1, 1) "," Then Text2.Text "" 'enleve le


premier si virgule
On Error GoTo lasuite
Text3.Text = ((Text2.Text - Text1.Text) / Text2.Text * 100)


lasuite:
End Sub


Private Sub TEXT2_KeyPress(KeyAscii As Integer)
'8 = TOUCHE RET ARR ; 46 TOUCHE POINT DECIMAL ;44 TOUCHE VIRGULE
If KeyAscii <> 8 And (KeyAscii < 48 Or KeyAscii > 57) Then
If KeyAscii = 44 Then
If InStr(1, Text2.Text, ",") Then KeyAscii = 0
ElseIf KeyAscii = 46 Then
If InStr(1, Text2.Text, ",") Then
KeyAscii = 0
Else
KeyAscii = 44
End If
Else
KeyAscii = 0
End If
End If
End Sub


Private Sub TEXT2_KeyUp(KeyCode As Integer, Shift As Integer)
'PVHT
On Error GoTo fin:

Text4.Text = Round((Text2.Text * TVA), 3)
Text6.Text = Text4.Text - Text2.Text
Text8.Text = ((Text2.Text - Text1.Text) / Text4.Text * 100)
Text7.Text = Text2.Text - Text1.Text
Text5.Text = Text4.Text / Text1.Text
fin:
End Sub


Private Sub TEXT4_Change()
'PVTTC
'PVTTC = PVHT X ( ( TVA + 100) / 100 )If Text4.Text "" Then Text2.Text "": Text6.Text = "":


Text5.Text = ""
If Len(Text4.Text) < 1 Then Exit Sub
Text4.Text = Trim(Text4.Text) 'enleve les espaces droite et gaucheIf Mid(Text4.Text, 1, 1) "," Then Text4.Text "" 'enleve le


premier si virgule




End Sub


Private Sub TEXT4_KeyPress(KeyAscii As Integer)
'8 = TOUCHE RET ARR ; 46 TOUCHE POINT DECIMAL ;44 TOUCHE VIRGULE
If KeyAscii <> 8 And (KeyAscii < 48 Or KeyAscii > 57) Then
If KeyAscii = 44 Then
If InStr(1, Text4.Text, ",") Then KeyAscii = 0
ElseIf KeyAscii = 46 Then
If InStr(1, Text4.Text, ",") Then
KeyAscii = 0
Else
KeyAscii = 44
End If
Else
KeyAscii = 0
End If
End If
End Sub


Private Sub TEXT4_KeyUp(KeyCode As Integer, Shift As Integer)
'PVTTC
On Error GoTo fin
Text2.Text = Round((Text4.Text / TVA), 3)
Text6.Text = Text4.Text - Text2.Text


Text8.Text = ((Text2.Text - Text1.Text) / Text4.Text * 100)
Text7.Text = Text2.Text - Text1.Text
Text5.Text = Text4.Text / Text1.Text
fin:
End Sub


Private Sub TEXT3_Change()
'TAUX DE MARQUE
'PVHT = (PAHT X 100)/(100 - TM)
'PAHT = PVHT - ((TM X PVHT)/100)
On Error GoTo fin
Text3.Text = Round(Text3.Text, 2)
fin:
End Sub


Private Sub Text7_Change() 'Enabled = False
'MARGE BRUTE
'MB = PVHT - PAHT
End Sub


Private Sub TEXT8_Change() 'Enabled = False
'TM GC
'TM-GC = 100 X ( ( PVHT - PAHT ) / PVTTC )
On Error GoTo fin
Text8.Text = Round(Text8.Text, 2)
fin:
End Sub


Private Sub TEXT6_Change() 'Enabled = False
'VALEUR TVA
'TVA = PVTTC - PVHT


On Error GoTo fin
Text6.Text = Round(Text6.Text, 3)


fin:
End Sub

1 réponse

Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
20 févr. 2005 à 12:15
ton problème vient des calculs avec zones non numériques. éviter espace dans les zones textes sinon ça plante les calculs.
donc à l'effacement ne pas mettre des espaces mais des zéros.
de même à la saisie faire des controles de numéricité plus poussé.

eviter de faire On Error GoTo Fin pour se simplifier la vie. ça cache le problème mais ça ne le solutionne pas pour autant.
toute division doit s'assurer que le diviseur ne soit pas égal à zéro à plus forte raison s'il est pas numérique:
Text8.Text = ((Text2.Text - Text1.Text) / Text4.Text * 100)

dans l'évênement Click des options boutons, les tests sont inutiles, étant donné que Value est forcément à True quand on est dans l'évênement et que l'autre se met automatiquement à False.
If Option2.Value = True Then
Option1.Value = False
TVA = 1.196
Text4.Text = Round((Text2.Text * TVA), 3)
End If

Daniel
0
Rejoignez-nous