faites une interface de calculatrice windows standard et insérez ceci:
Source / Exemple :
Private signe, retour As Byte
Private N1, N2, mem As Single
Private sepdec, zero As String
Private Sub Form_Load()
zero = "0"
sepdec = ","
txtAfficher.Text = "0,"
retour = 1
End Sub
Private Sub cmdRetour_Click()
If txtAfficher.Text <> "0" Then
If Len(txtAfficher.Text) = 1 Then
txtAfficher.Text = "0,"
retour = 1
Else
txtAfficher.Text = Left(txtAfficher.Text, Len(txtAfficher.Text) - 1)
End If
End If
End Sub
Private Sub cmdSigne_Click()
txtAfficher.Text = Not (Val(txtAfficher.Text)) - 1
retour = 1
End Sub
Private Sub cmdVirgule_Click()
If retour = 0 Then
txtAfficher.Text = txtAfficher.Text + sepdec
Else
txtAfficher.Text = sepdec
retour = 0
End If
End Sub
' Initialisation des commandes de 0 à 9
Private Sub cmd0_Click()
If retour = 0 Then
txtAfficher.Text = txtAfficher.Text + CStr(0)
Else
txtAfficher.Text = CStr(0)
retour = 0
End If
End Sub
Private Sub cmd1_Click()
If retour = 0 Then
txtAfficher.Text = txtAfficher.Text + CStr(1)
Else
txtAfficher.Text = CStr(1)
retour = 0
End If
End Sub
Private Sub cmd2_Click()
If retour = 0 Then
txtAfficher.Text = txtAfficher.Text + CStr(2)
Else
txtAfficher.Text = CStr(2)
retour = 0
End If
End Sub
Private Sub cmd3_Click()
If retour = 0 Then
txtAfficher.Text = txtAfficher.Text + CStr(3)
Else
txtAfficher.Text = CStr(3)
retour = 0
End If
End Sub
Private Sub cmd4_Click()
If retour = 0 Then
txtAfficher.Text = txtAfficher.Text + CStr(4)
Else
txtAfficher.Text = CStr(4)
retour = 0
End If
End Sub
Private Sub cmd5_Click()
If retour = 0 Then
txtAfficher.Text = txtAfficher.Text + CStr(5)
Else
txtAfficher.Text = CStr(5)
retour = 0
End If
End Sub
Private Sub cmd6_Click()
If retour = 0 Then
txtAfficher.Text = txtAfficher.Text + CStr(6)
Else
txtAfficher.Text = CStr(6)
retour = 0
End If
End Sub
Private Sub cmd7_Click()
If retour = 0 Then
txtAfficher.Text = txtAfficher.Text + CStr(7)
Else
txtAfficher.Text = CStr(7)
retour = 0
End If
End Sub
Private Sub cm8_Click()
If retour = 0 Then
txtAfficher.Text = txtAfficher.Text + CStr(8)
Else
txtAfficher.Text = CStr(8)
retour = 0
End If
End Sub
Private Sub cmd9_Click()
If retour = 0 Then
txtAfficher.Text = txtAfficher.Text + CStr(9)
Else
txtAfficher.Text = CStr(9)
retour = 0
End If
End Sub
Private Sub CmdC_Click()
txtAfficher.Text = "0,"
N1 = 0
retour = 1
End Sub
'Assignation des valeurs en entrée des opérands
Private Sub cmdDivision_Click()
N1 = Val(txtAfficher.Text)
retour = 1
signe = 1
End Sub
Private Sub cmdProduit_Click()
N1 = Val(txtAfficher.Text)
retour = 1
signe = 2
End Sub
Private Sub cmdAddition_Click()
N1 = Val(txtAfficher.Text)
retour = 1
signe = 3
End Sub
Private Sub cmdSoustraction_Click()
N1 = Val(txtAfficher.Text)
retour = 1
signe = 4
End Sub
' La sélection de l'opérand
Private Sub cmdResultat_Click()
N2 = Val(txtAfficher.Text)
Dim virgule As Integer
Select Case signe
Case 1
If Val(txtAfficher.Text) <> 0 Then
N1 = N1 / N2
Else
N1 = "Erreur : nombre infini positif."
End If
Case 2
N1 = N1 * N2
virgule = InStr(CStr(N1), ",")
If virgule = 0 Then
zero = CStr(N1)
txtAfficher.Text = zero & virgule
Else
zero = CStr(N1)
txtAfficher.Text = zero
End If
Case 3
N1 = N1 + N2
virgule = InStr(CStr(N1), ",")
If virgule = 0 Then
zero = CStr(N1)
txtAfficher.Text = zero & virgule
Else
zero = CStr(N1)
txtAfficher.Text = zero
End If
Case 4
N1 = N1 - N2
virgule = InStr(CStr(N1), ",")
If virgule = 0 Then
zero = CStr(N1)
txtAfficher.Text = zero & virgule
Else
zero = CStr(N1)
txtAfficher.Text = zero
End If
End Select
txtAfficher.Text = CStr(N1)
retour = 1
End Sub
' Fractions et racine carré
Private Sub cmdSqrt_Click()
txtAfficher.Text = Sqr(txtAfficher.Text)
retour = 1
End Sub
Private Sub cmdPourcentage_Click()
txtAfficher.Text = Val(txtAfficher.Text) / 100
retour = 1
End Sub
Private Sub cmdFraction_Click()
If Val(txtAfficher.Text) = 0 Then
txtAfficher.Text = "Erreur : nombre infini positif."
retour = 1
Else
If Val(txtAfficher.Text) <> 0 Then
txtAfficher.Text = 1 / CStr(Val(txtAfficher.Text))
retour = 1
End If
End If
End Sub
' Gestion des touches mémoires
Private Sub cmdMs_Click()
mem = Val(txtAfficher.Text)
txtMem.Text = "M"
retour = 1
End Sub
Private Sub cmdMr_Click()
txtAfficher.Text = mem
retour = 1
End Sub
Private Sub cmdMc_Click()
txtMem.Text = ""
mem = 0
retour = 1
End Sub
Private Sub cmdM_Click()
mem = mem + Val(txtAfficher.Text)
retour = 1
End Sub
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.