Salut
utilise le double.parse
voila un petit ex de calculatrice
avec 10 boutons de 0 à 9
le bouton decimal et le bouton + et le bouton
=
Public Class Form1
Private operand1 As String
Private operand2 As String
Private op As Boolean
Private oper As String
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
operand1 = String.Empty
operand2 = String.Empty
oper = String.Empty
op = False
End Sub
Private Sub Button0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button0.Click, Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click
If Not op Then
operand1 = String.Concat(operand1, DirectCast(sender, Button).Text)
Labelresult.Text = operand1
Else
operand2 = String.Concat(operand2, DirectCast(sender, Button).Text)
Labelresult.Text = operand2
End If
End Sub
Private Sub Buttondec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttondec.Click
If oper = String.Empty Then
If Not operand1.Contains(".") Then
operand1 = String.Concat(operand1, DirectCast(sender, Button).Text)
Labelresult.Text = operand1
End If
Labelresult.Text = operand1
Else
If Not operand2.Contains(".") Then
operand2 = String.Concat(operand2, DirectCast(sender, Button).Text)
Labelresult.Text = operand2
End If
End If
End Sub
Private Sub Buttonplus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonplus.Click
oper = DirectCast(sender, Button).Text
Dim val1, val2 As Double
If Not operand2 = String.Empty Then
val1 = Double.Parse(operand1)
val2 = Double.Parse(operand2)
Labelresult.Text = (val1 + val2).ToString
op = False
operand1 = Labelresult.Text
operand2 = String.Empty
End If
op = True
End Sub
Private Sub Buttonegale_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonegale.Click
Dim val1, val2 As Double
If op Then
Select Case oper
Case "+"
val1 = Double.Parse(operand1)
val2 = Double.Parse(operand2)
Labelresult.Text = (val1 + val2).ToString
End Select
End If
End Sub
End Class