Comment faire une calculatrice avec vb

Fermé
Aymen - 17 juin 2005 à 16:48
 tarik azrhirh - 11 avril 2009 à 13:41
salut je me demande comment faire une calculatrice avec visual basic
A voir également:

5 réponses

walid524 Messages postés 20 Date d'inscription lundi 3 mai 2004 Statut Membre Dernière intervention 12 avril 2007
10 févr. 2007 à 14:29
Dim S1 As Double '2éme operande
Dim S2 As Double '1er operande
Dim Oper As Integer 'indique la nature de l'operation a faire.On en aura besoin dans le Egal_Click()
Dim Oper2 As Boolean 'Indique s'il y'a 2 operateurs ou 1 seul
Dim Xbase As Integer


'ça c'est pour le boutton +
Private Sub Add_Click()
Oper = 1
If Oper2 = False Then
S2 = S1
S1 = 0
Oper2 = True
End If
End Sub

'ça c'est pour le boutton 1
Private Sub B1_Click()
S1 = S1 * 10 + 1
Val.Text = S1
End Sub


à vous de jouer maintenant
29
comment faire un calculatrice
13
MohipArrasol
8 mars 2009 à 22:45
command10 c'est le boutton 0
command2 c'est le boutton 2
....
command9 c'est le boutton 9
op1 c'est le boutton +
op2 c'est le boutton -
op3 c'est le boutton *
op4 c'est le boutton /
label ou le resultat sera affiché
etc

Voici le code:
Dim byteoperation As Byte
Dim typeoperation As Byte
Dim nbr1 As Double
Dim nbrvrg As Byte
Dim fctr As Double
Private Sub CommandButton18_Click()
If label.Caption <> 0 Then
label.Caption = 1 / label.Caption
Else
MsgBox "Division par zéro impossible"
End If
End Sub
Private Sub CommandButton21_Click()
For i = 1 To Len(label)
If Mid(label, i, 1) = "." Then
nbrvrg = nbrvrg + 1
End If
Next i
If nbrvrg = 0 Then
label = label & "."
Else
label = label
End If
nbrvrg = 0
End Sub
Private Sub CommandButton24_Click()
byteoperation = 5
If typeoperation = 1 Then
label = label + nbr1
Else
If typeoperation = 2 Then
label = -1 * label + nbr1
Else
If typeoperation = 3 Then
label = label * nbr1
Else
If typeoperation = 4 Then
If label <> 0 Then
label = nbr1 / label
Else
MsgBox "Division par zéro impossible"
End If
End If
End If
End If
End If
End Sub
Private Sub CommandButton30_Click()
label = 0
End Sub
Private Sub CommandButton6_Click()
If label.Caption >= 0 Then
label.Caption = (label.Caption) ^ 0.5
Else
MsgBox "ce nombre doit être positive"
End If
End Sub
Private Sub fct_Click()
fctr = 1
For i = 1 To label.Caption
fctr = fctr * i
Next i
label.Caption = fctr
End Sub
Private Sub op1_Click()
typeoperation = 1
byteoperation = 1
nbr1 = label.Caption
End Sub
Private Sub op2_Click()
typeoperation = 2
byteoperation = 2
nbr1 = label.Caption
End Sub
Private Sub op3_Click()
typeoperation = 3
byteoperation = 3
nbr1 = label.Caption
End Sub
Private Sub op4_Click()
typeoperation = 4
byteoperation = 4
nbr1 = label.Caption
End Sub
Private Sub commande1_Click()
If byteoperation = 0 Then
label.Caption = label.Caption & 1
Else
label.Caption = 1
byteoperation = 0
End If
End Sub
Private Sub commande2_Click()
If byteoperation = 0 Then
label.Caption = label.Caption & 2
Else
label.Caption = 2
byteoperation = 0
End If
End Sub
Private Sub commande3_Click()
If byteoperation = 0 Then
label.Caption = label.Caption & 3
Else
label.Caption = 3
byteoperation = 0
End If
End Sub
Private Sub commande4_Click()
If byteoperation = 0 Then
label.Caption = label.Caption & 4
Else
label.Caption = 4
byteoperation = 0
End If
End Sub
Private Sub commande5_Click()
If byteoperation = 0 Then
label.Caption = label.Caption & 5
Else
label.Caption = 5
byteoperation = 0
End If
End Sub
Private Sub commande6_Click()
If byteoperation = 0 Then
label.Caption = label.Caption & 6
Else
label.Caption = 6
byteoperation = 0
End If
End Sub
Private Sub commande7_Click()
If byteoperation = 0 Then
label.Caption = label.Caption & 7
Else
label.Caption = 7
byteoperation = 0
End If
End Sub
Private Sub commande8_Click()
If byteoperation = 0 Then
label.Caption = label.Caption & 8
Else
label.Caption = 8
byteoperation = 0
End If
End Sub
Private Sub commande9_Click()
If byteoperation = 0 Then
label.Caption = label.Caption & 9
Else
label.Caption = 9
byteoperation = 0
End If
End Sub
Private Sub commande10_Click()
If byteoperation = 0 Then
label.Caption = label.Caption & 0
Else
label.Caption = 0
byteoperation = 0
End If
End Sub
Private Sub ra_Click()
If Len(label.Caption) <> 1 Then
label.Caption = Left(label.Caption, Len(label.Caption) - 1)
Else
label.Caption = 0
End If
End Sub
Private Sub siop_Click()
label.Caption = -label.Caption
End Sub
0
NaNaChan > MohipArrasol
12 mars 2009 à 22:40
Bonsoir,

J'ai un gros probleme, je dois créer une calculatrice en VB pour mon BTS dans un mois, mais je n'y arrive pas.
Peux tu m'aider stp ?

C'est urgent et je t'en serai reconnaisante.

Merci bien.
0
isaacfromorocco
19 juin 2008 à 22:10
Voici le code d'une calculatrice ke jai creé mais apre c les command originale ke jai utiliser jai pa changer le caption vous pouver creé une calculatrice avec se code je veu dire le meme mais fai attention les buttons doient etre les meme :)

command1 c'est le bouton 1 remarque: byteoperation = 0 sa veu dire ona pa encore clické a aucune operation
+ - * ou /
command2 c'est le bouton 2 byteoperation = 1 veu dire kona clické sur une operation
typeoperation = 1 ca veu dire c loperation +
...................................... typeoperation = 2 c loperation - typeoperation= 3 c * et typeoperation=4 c /
...................................
.......................................
....................................
.....................................
.....................................
.......................................
command10 c'est le bouton 0
-----------------------------------------
command11 c'est le boutton C (effacer)
command12 c'est le button (+)
command13 c'est le button (-)
command14 c'est le button (*)
command15 c'est le button (/)
command16 c'est le button (=)
------------------------------------------------------------------------------------------------------------
(voici le code)

Dim byteoperation As Byte
Dim typeoperation As Byte
Dim nbr1 As Double
Dim nbr2 As Double
Dim nbr3 As Double

Private Sub Command1_Click()
If byteoperation = 0 Then
Text1.Text = Text1.Text + Str(1)
Else
Text1.Text = Str(1)
byteoperation = 0
End If
End Sub

Private Sub Command10_Click()
If byteoperation = 0 Then
Text1.Text = Text1.Text + Str(0)
Else
Text1.Text = Str(0)
byteoperation = 0
End If
End Sub

Private Sub Command11_Click()
Text1.Text = ""
End Sub

Private Sub Command12_Click()
byteoperation = 1
typeoperation = 1
nbr1 = Text1.Text
End Sub

Private Sub Command13_Click()
byteoperation = 1
typeoperation = 2
nbr1 = Text1.Text
End Sub

Private Sub Command14_Click()
byteoperation = 1
typeoperation = 3
nbr1 = Text1.Text
End Sub

Private Sub Command15_Click()
byteoperation = 1
typeoperation = 4
nbr1 = Text1.Text
End Sub

Private Sub Command16_Click()
nbr2 = Text1.Text
If typeoperation = 1 Then
nbr3 = nbr1 + nbr2
Text1.Text = Val(nbr3)

End If
nbr2 = Text1.Text
If typeoperation = 2 Then
nbr3 = nbr1 - nbr2
Text1.Text = Val(nbr3)
End If
nbr2 = Text1.Text
If typeoperation = 3 Then
nbr3 = nbr1 * nbr2
Text1.Text = Val(nbr3)
End If

nbr2 = Text1.Text
If typeoperation = 4 Then
nbr3 = nbr1 / nbr2
Text1.Text = Val(nbr3)
End If
End Sub

Private Sub Command2_Click()
If byteoperation = 0 Then
Text1.Text = Text1.Text + Str(2)
Else
Text1.Text = Str(2)
byteoperation = 0
End If
End Sub

Private Sub Command3_Click()
If byteoperation = 0 Then
Text1.Text = Text1.Text + Str(3)
Else
Text1.Text = Str(3)
byteoperation = 0
End If
End Sub

Private Sub Command4_Click()
If byteoperation = 0 Then
Text1.Text = Text1.Text + Str(4)
Else
Text1.Text = Str(4)
byteoperation = 0
End If
End Sub

Private Sub Command5_Click()
If byteoperation = 0 Then
Text1.Text = Text1.Text + Str(5)
Else
Text1.Text = Str(6)
byteoperation = 0
End If
End Sub

Private Sub Command6_Click()
If byteoperation = 0 Then
Text1.Text = Text1.Text + Str(6)
Else
Text1.Text = Str(6)
byteoperation = 0
End If
End Sub

Private Sub Command7_Click()
If byteoperation = 0 Then
Text1.Text = Text1.Text + Str(7)
Else
Text1.Text = Str(7)
byteoperation = 0
End If
End Sub

Private Sub Command8_Click()
If byteoperation = 0 Then
Text1.Text = Text1.Text + Str(8)
Else
Text1.Text = Str(8)
byteoperation = 0
End If
End Sub

Private Sub Command9_Click()
If byteoperation = 0 Then
Text1.Text = Text1.Text + Str(9)
Else
Text1.Text = Str(9)
byteoperation = 0
End If
End Sub
7
merçi
0
comment faire une calculatrice
5
Dim byteoperation As Byte
Dim typeoperation As Byte
Dim nbr1 As Integer
Private Sub CommandButton24_Click()
If typeoperation = 1 Then
label = label + nbr1
Else
If typeoperation = 2 Then
label = -1 * label + nbr1
Else
If typeoperation = 3 Then
label = label * nbr1
Else
If typeoperation = 4 Then
If label <> 0 Then
label = nbr1 / label
Else
MsgBox "Division par zéro impossible"
End If
End If
End If
End If
End If
End Sub
Private Sub CommandButton30_Click()
label = 0
End Sub
Private Sub op1_Click()
typeoperation = 1
byteoperation = 1
nbr1 = label.Caption
End Sub
Private Sub op2_Click()
typeoperation = 2
byteoperation = 2
nbr1 = label.Caption
End Sub
Private Sub op3_Click()
typeoperation = 3
byteoperation = 3
nbr1 = label.Caption
End Sub
Private Sub op4_Click()
typeoperation = 4
byteoperation = 4
nbr1 = label.Caption
End Sub
Private Sub commande1_Click()
If byteoperation = 0 Then
label.Caption = label.Caption + Str(1)
Else
label.Caption = Str(1)
byteoperation = 0
End If
End Sub
Private Sub commande2_Click()
If byteoperation = 0 Then
label.Caption = label.Caption + Str(2)
Else
label.Caption = Str(2)
byteoperation = 0
End If
End Sub
Private Sub commande3_Click()
If byteoperation = 0 Then
label.Caption = label.Caption + Str(3)
Else
label.Caption = Str(3)
byteoperation = 0
End If
End Sub
Private Sub commande4_Click()
If byteoperation = 0 Then
label.Caption = label.Caption + Str(4)
Else
label.Caption = Str(4)
byteoperation = 0
End If
End Sub
Private Sub commande5_Click()
If byteoperation = 0 Then
label.Caption = label.Caption + Str(5)
Else
label.Caption = Str(5)
byteoperation = 0
End If
End Sub
Private Sub commande6_Click()
If byteoperation = 0 Then
label.Caption = label.Caption + Str(6)
Else
label.Caption = Str(6)
byteoperation = 0
End If
End Sub
Private Sub commande7_Click()
If byteoperation = 0 Then
label.Caption = label.Caption + Str(7)
Else
label.Caption = Str(7)
byteoperation = 0
End If
End Sub
Private Sub commande8_Click()
If byteoperation = 0 Then
label.Caption = label.Caption + Str(8)
Else
label.Caption = Str(8)
byteoperation = 0
End If
End Sub
Private Sub commande9_Click()
If byteoperation = 0 Then
label.Caption = label.Caption + Str(9)
Else
label.Caption = Str(9)
byteoperation = 0
End If
End Sub
Private Sub commande10_Click()
If byteoperation = 0 Then
label.Caption = label.Caption + Str(0)
Else
label.Caption = Str(0)
byteoperation = 0
End If
End Sub
0
tarik azrhirh > Meski hicham
11 avril 2009 à 13:41
Public Class Form1




Dim y, x
Dim operation
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = TextBox1.Text + "1"
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = TextBox1.Text + "2"
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = TextBox1.Text + "3"
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TextBox1.Text = TextBox1.Text + "4"
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
TextBox1.Text = TextBox1.Text + "5"
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
TextBox1.Text = TextBox1.Text + "6"
End Sub


Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
TextBox1.Text = TextBox1.Text + "7"
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
TextBox1.Text = TextBox1.Text + "8"
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
TextBox1.Text = TextBox1.Text + "9"
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
TextBox1.Text = TextBox1.Text + "0"
End Sub

Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
TextBox1.Visible = False
End Sub

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
x = Val(TextBox1.Text)
TextBox1.Text = " "
operation = 1
End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
Select Case operation
Case 1
y = Val(TextBox1.Text)
TextBox1.Text = x + y
Case 2
y = Val(TextBox1.Text)
TextBox1.Text = x - y
Case 3
y = Val(TextBox1.Text)
TextBox1.Text = x * y
Case 4
y = Val(TextBox1.Text)
TextBox1.Text = x / y
If y = 0 Then
MsgBox("y ne peut pas etre egal a 0")
End If
End Select
End Sub

Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
TextBox1.Text = " "
x = 0
y = 0
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
x = Val(TextBox1.Text)
TextBox1.Text = " "
operation = 2
End Sub

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
x = Val(TextBox1.Text)
TextBox1.Text = " "
operation = 3
End Sub

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
x = Val(TextBox1.Text)
TextBox1.Text = " "
operation = 4
End Sub

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
Button10.Visible = False
Button21.Visible = False
Button22.Visible = False
Button23.Visible = False
Button28.Visible = False
Button27.Visible = False
Button24.Visible = False
Button25.Visible = False
Button26.Visible = False
Button29.Visible = False
Button20.Visible = False
Else
Button10.Visible = True
Button21.Visible = True
Button22.Visible = True
Button23.Visible = True
Button28.Visible = True
Button27.Visible = True
Button24.Visible = True
Button25.Visible = True
Button26.Visible = True
Button29.Visible = True
Button20.Visible = True
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RadioButton1.Checked = True
End Sub

Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click
TextBox1.Text = Math.Cos(TextBox1.Text)
End Sub

Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
TextBox1.Text = Math.Log(TextBox1.Text)
End Sub

Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
TextBox1.Text = Math.Exp(TextBox1.Text)
End Sub

Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Click
TextBox1.Text = Math.Sqrt(TextBox1.Text)
End Sub

Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click
TextBox1.Text = Math.Sin(TextBox1.Text)
End Sub

Private Sub Button26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button26.Click
TextBox1.Text = Math.Tan(TextBox1.Text)
End Sub

Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
TextBox1.Visible = True
End Sub
End Class
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
random Messages postés 1612 Date d'inscription vendredi 26 novembre 2004 Statut Membre Dernière intervention 30 mars 2006 155
17 juin 2005 à 16:53
tu crées un frame avec un groupe de bouton pour les chiffres
et un autre pour les opérations
un évenement sur appui bouton va inscrire à la fin d'une zone texte
le chiffre correspondant au bouton pressé
l'appui sur une touche opération va libérer l'opération en cours
et nourrir un compteur de résultat intercalaire
l'appui sur égal vide tout et affiche résultat
4