Rechercher : dans
Par :

Comment faire une calculatrice avec vb

Aymen, le 17 jun 2005 à 16:48:34
 Signaler ce message aux modérateurs

Salut je me demande comment faire une calculatrice avec visual basic

Meilleures réponses pour « comment faire une calculatrice avec vb » dans :
Google - Fonction calculatrice VoirGoogle dispose d'une calculatrice intégrée. Pour l'utiliser, il suffit simplemement d'entrer une expression dans le champ de saisie et de lancer la recherche ! Cette fonction est aussi accessible à partir de la barre Google ou des navigateurs...
Télécharger Ma Calculatrice VoirWindows propose par défaut une calculatrice avec des fonctions dites scientifiques mais tout de même incomplètes. MaCalculatrice est une calculatrice beaucoup plus complète et évoluée. C'est une calculatrice graphique et comprend divers modules...

1

random, le 17 jun 2005 à 16:53:29

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
elle est pas belle, la vie ?

2

tony, le 17 jun 2005 à 17:02:07

Vous voulez pas kon vous ponde votre programme en entier pdt que vous y êtes !!!!

réfléchissez un peu à votre problème avant de poster vos messages!! on vous aidera si vous bloquez sur une partie de votre code !!!!

bon courage

tony

3

khadija, le 10 fév 2007 à 13:36:37
  • +2

Comment faire un calculatrice

16

MohipArrasol, le 8 mar 2009 à 22:45:58

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

17

NaNaChan, le 12 mar 2009 à 22:40:33

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.

4

khadija, le 10 fév 2007 à 13:37:49

5

walid524, le 10 fév 2007 à 14:29:29
  • +11

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

6

Hicham, le 5 avr 2007 à 19:29:12

Ben jvous conseil ce site et vous trouverez tout dont vous avé besoin et la prochaine il faut etre capabl tt seul voila le site : www.vbfrance.com/gma/calculatrice

7

Mario1095, le 23 sep 2007 à 11:24:29

Ca fonctionne avec VBA ???

8

smi, le 30 mar 2008 à 15:08:37

Svp si vous pourriez m'aider pour creer un programme window en VB(calculatrice) ca seré sympa de votre part et marci d'avance

20

ed, le 16 avr 2009 à 22:59:21

Ya na9ala 6ay7ine 3la j9ir fi hade site matkoune ghir nta a ILAISS kikikikiki

9

isaacfromorocco, le 19 jun 2008 à 22:10:08
  • +2

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

10

prettygirl, le 22 jui 2008 à 00:34:30

Merçi

11

Mario1095, le 31 oct 2008 à 19:06:23

Résolu
Lock Ce forum n'est pas un GSM!
No Flood
No Debilitated
To reflect before acting!
Evitez les fautes!
/!\\ Quand ça déconne, je préviens les modérateurs/!\\

Mon Blog : blog.ifrance.com/mapsp95
Mon forum : mapsp95.playsboard.com
Mon site : mapsp95.ifrance.com

12

sannoun, le 20 nov 2008 à 14:34:51
  • +1

Comment faire une calculatrice

15

Meski hicham, le 13 fév 2009 à 23:04:51
  • +1

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

18

tarik azrhirh, le 11 avr 2009 à 13:41:58

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

19

smokako, le 11 avr 2009 à 19:13:00

Slt

je veux le code associé avec la bouton decimal, hexadecimal, binaire, octale, log.. (le language est le vb)
merci d'avance

21

 bigmat, le 17 avr 2009 à 00:23:46
  • +1

Rien de tout ca.
pour une calculatrice, il faut faire :
Demarrer > accessoires > calculatrice.

Collection CommentÇaMarche.net