Calcul Décimale Text1 + Text 2

Résolu
Sinsitrus Messages postés 849 Date d'inscription samedi 11 juin 2005 Statut Membre Dernière intervention 21 août 2015 - 24 juil. 2014 à 20:47
Sinsitrus Messages postés 849 Date d'inscription samedi 11 juin 2005 Statut Membre Dernière intervention 21 août 2015 - 25 juil. 2014 à 01:01
Salut à tous !

Je ne comprends pas pourquoi j'ai un gros problème de calcul :
Private Sub Text1_LostFocus()
Text1 = Format(Text1, "Standard")
End Sub

Private Sub Text2_LostFocus()
Text2 = Format(Text2, "Standard")
End Sub

Private Sub Text3_LostFocus()
Text3 = Format(Text3, "Standard")
End Sub

Private Sub Timer1_Timer()
Total = Val(Text1) + Val(Text2) + Val(Text3)

Label1 = Format(Total, "Standard")
Label2 = FormatNumber(Total, 2, True, True, True)
Label3 = FormatCurrency(Total, 2, True, True, True)
End Sub

Quelque soit les chiffres que je met je reviens toujours à un gros hic et je ne comprends pas pourquoi.
Pouvez-vous m'aider svp ?

Text1 = 10 000,00
Text2 = 9 000,00
Text3 = 10 000,00
Me renvois 29,00

et

Text1 = 10,00
Text2 = 9,00
Text3 = 10,00
Me renvois 29,00

Merci

----------
OS : Windows 7 Pro 64 Bit
Platforme : Visual Basic 6.0

3 réponses

cs_petchy Messages postés 710 Date d'inscription jeudi 20 février 2003 Statut Membre Dernière intervention 19 mai 2015 4
24 juil. 2014 à 22:50
salut
essaye sa

Total = CDbl(Text1) + CDbl(Text2) + CDbl(Text3)
1
NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 159
24 juil. 2014 à 23:07
Je pense que ton problème vient de l'espace :
"10 000,00"
essayes plutôt :
"10000,00"
0
Sinsitrus Messages postés 849 Date d'inscription samedi 11 juin 2005 Statut Membre Dernière intervention 21 août 2015
25 juil. 2014 à 01:01
Merci cs_petchy, le CDbl fonctionne parfaitement !
Mon problème est résolu et effectivement NHenry, l'espace me créait un soucis (c'est ce qui arrive lorsqu'on utilise le "Format Standard", il crée un séparateur de millier et le calcul y est impossible sauf avec le CDbl que m'a enseigné cs_petchy :))

Encore une fois merci !
0
Rejoignez-nous