Saros
Messages postés921Date d'inscriptionvendredi 20 décembre 2002StatutMembreDernière intervention23 septembre 2010
-
19 janv. 2004 à 18:41
neamar
Messages postés26Date d'inscriptionvendredi 9 septembre 2005StatutMembreDernière intervention12 avril 2009
-
16 mars 2008 à 12:49
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.
neamar
Messages postés26Date d'inscriptionvendredi 9 septembre 2005StatutMembreDernière intervention12 avril 2009 16 mars 2008 à 12:49
Salut
Le problème de ta calculette, c'est qu'elle ne permet pas de faire des gros calculs : par exemple, avec parenthèses et gestion des priorités...
Si tu veux l'améliorer, j'ai posté une source qui va dans ce sens : http://www.vbfrance.com/code.aspx?ID=46070
michmuch2000
Messages postés33Date d'inscriptionvendredi 1 août 2003StatutMembreDernière intervention26 août 2008 30 janv. 2004 à 02:25
Si ca t'interesse... ça récupère le clavier numérique et ca calcule.
une form, deux label : calcul et visu et un module.
Dim ch1 As Single
Dim ch2 As Single
Dim tot As Single
Dim Addition As Boolean
Dim Multiplication As Boolean
Dim Division As Boolean
Dim Soustraction As Boolean
Dim ope As Boolean
Private Sub Form_Load()
'calcul = calcul & Chr(KeyAscii)
calcul = "0"
End Sub
Private Sub form_KeyPress(KeyAscii As Integer)
calcul = calcul & Chr(KeyAscii)
visu = visu & Chr(KeyAscii)
If Left(calcul, 1) "0" Then calcul Right(calcul, Len(calcul) - 1)
If ope True Then calcul Right(calcul, 1): ope = False
If KeyAscii 27 Then calcul "0": visu = "": ch1 = 0: ch2 = 0: tot = 0
If KeyAscii = 43 Then
ch1 virgule(Left(calcul, Len(calcul) - 1)): ope True: calcul = Left(calcul, Len(calcul) - 1)
'calcul = "0"
Addition = True
End If
If KeyAscii = 45 Then
ch1 virgule(Left(calcul, Len(calcul) - 1)): ope True: calcul = Left(calcul, Len(calcul) - 1)
Soustraction = True
'calcul = "0"
End If
If KeyAscii = 47 Then
ch1 virgule(Left(calcul, Len(calcul) - 1)): ope True: calcul = Left(calcul, Len(calcul) - 1)
Division = True
'calcul = "0"
End If
If KeyAscii = 42 Then
ch1 virgule(Left(calcul, Len(calcul) - 1)): ope True: calcul = Left(calcul, Len(calcul) - 1)
Multiplication = True
'calcul = "0"
End If
If KeyAscii = 13 Then
If Multiplication = True Then
ch2 = virgule(calcul)
tot = ch1 * ch2
calcul = tot
visu = visu & "=(" & tot & ") "
End If
If Division = True Then
ch2 = virgule(calcul)
tot = ch1 / ch2
calcul = tot
visu = visu & "=(" & tot & ") "
End If
If Soustraction = True Then
ch2 = virgule(calcul)
tot = ch1 - ch2
calcul = tot
visu = visu & "=(" & tot & ") "
End If
If Addition = True Then
ch2 = virgule(calcul)
tot = ch1 + ch2
calcul = tot
visu = visu & "=(" & tot & ") "
End If
Addition = False
Multiplication = False
Division = False
Soustraction = False
End If
'text2 = KeyAscii
End Sub
'************************
'et ceci dans un module
'************************
Function virgule(entree As String) As Single
If InStr(1, entree, ".") Then virgule Replace(entree, ".", ",") Else virgule CSng(entree)
End Function
Saros
Messages postés921Date d'inscriptionvendredi 20 décembre 2002StatutMembreDernière intervention23 septembre 2010 19 janv. 2004 à 18:41
Au moins, ça a le mérite d'être simple, claire et précis, sans lacune...
Rien à ajouter... 9/10
Saros
16 mars 2008 à 12:49
Le problème de ta calculette, c'est qu'elle ne permet pas de faire des gros calculs : par exemple, avec parenthèses et gestion des priorités...
Si tu veux l'améliorer, j'ai posté une source qui va dans ce sens : http://www.vbfrance.com/code.aspx?ID=46070
30 janv. 2004 à 02:25
une form, deux label : calcul et visu et un module.
Dim ch1 As Single
Dim ch2 As Single
Dim tot As Single
Dim Addition As Boolean
Dim Multiplication As Boolean
Dim Division As Boolean
Dim Soustraction As Boolean
Dim ope As Boolean
Private Sub Form_Load()
'calcul = calcul & Chr(KeyAscii)
calcul = "0"
End Sub
Private Sub form_KeyPress(KeyAscii As Integer)
calcul = calcul & Chr(KeyAscii)
visu = visu & Chr(KeyAscii)
If Left(calcul, 1) "0" Then calcul Right(calcul, Len(calcul) - 1)
If ope True Then calcul Right(calcul, 1): ope = False
If KeyAscii 27 Then calcul "0": visu = "": ch1 = 0: ch2 = 0: tot = 0
If KeyAscii = 43 Then
ch1 virgule(Left(calcul, Len(calcul) - 1)): ope True: calcul = Left(calcul, Len(calcul) - 1)
'calcul = "0"
Addition = True
End If
If KeyAscii = 45 Then
ch1 virgule(Left(calcul, Len(calcul) - 1)): ope True: calcul = Left(calcul, Len(calcul) - 1)
Soustraction = True
'calcul = "0"
End If
If KeyAscii = 47 Then
ch1 virgule(Left(calcul, Len(calcul) - 1)): ope True: calcul = Left(calcul, Len(calcul) - 1)
Division = True
'calcul = "0"
End If
If KeyAscii = 42 Then
ch1 virgule(Left(calcul, Len(calcul) - 1)): ope True: calcul = Left(calcul, Len(calcul) - 1)
Multiplication = True
'calcul = "0"
End If
If KeyAscii = 13 Then
If Multiplication = True Then
ch2 = virgule(calcul)
tot = ch1 * ch2
calcul = tot
visu = visu & "=(" & tot & ") "
End If
If Division = True Then
ch2 = virgule(calcul)
tot = ch1 / ch2
calcul = tot
visu = visu & "=(" & tot & ") "
End If
If Soustraction = True Then
ch2 = virgule(calcul)
tot = ch1 - ch2
calcul = tot
visu = visu & "=(" & tot & ") "
End If
If Addition = True Then
ch2 = virgule(calcul)
tot = ch1 + ch2
calcul = tot
visu = visu & "=(" & tot & ") "
End If
Addition = False
Multiplication = False
Division = False
Soustraction = False
End If
'text2 = KeyAscii
End Sub
'************************
'et ceci dans un module
'************************
Function virgule(entree As String) As Single
If InStr(1, entree, ".") Then virgule Replace(entree, ".", ",") Else virgule CSng(entree)
End Function
19 janv. 2004 à 18:41
Rien à ajouter... 9/10
Saros