我无法在TextBox上显示算术运算符符号

时间:2014-04-15 05:08:49

标签: vb.net-2010

我是VB.NET的初学者。我使用VS Express Studio 2010创建了一个简单的计算器程序。所有算术运算都正常但我无法在TextBox上显示运算符符号。请验证我的代码&建议我做一些修改。

Public Class Form1

Dim Value1, Value2 As Double

Dim Value3, Value4 As Double

Dim Value5, Value6 As Double

Dim Valuex, Valuey As Double

Dim Symbol As String




Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


End Sub


Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub
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 Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click


    TextBox1.Text = TextBox1.Text & "."

End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bclear.Click

    TextBox1.Clear()

End Sub


Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Badd.Click

    Value1 = Val(TextBox1.Text)

    Symbol = "+"

    TextBox1.Text = ""



End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bsub.Click

    Value1 = Val(TextBox1.Text)

    Symbol = "-"

    TextBox1.Text = ""



End Sub

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bmul.Click
    Value1 = Val(TextBox1.Text)

    Symbol = "*"

    TextBox1.Text = ""



End Sub
Public Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bdiv.Click

    Value1 = Val(TextBox1.Text)
    Symbol = "/"

    If Symbol = "/" Then
        Value4 = Value1    'To calculate the % we assign Value1 to Value4   

    End If

    TextBox1.Text = ""


End Sub



Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bpercent.Click



    Value5 = Val(TextBox1.Text)


    Value6 = (Value4 / Value5) * 100


    TextBox1.Text = Value6 'This will display the % when two numbers are divided & the % button is clicked

    '---------------------------------------------------------------------------------------------------------------------------------


    If Symbol = "%" Then
        Valuey = Valuex * 100

        TextBox1.Text = Valuey


        'This will display the Value of the percentage when % button is clicked
        ' when two values are divided & the result is displayed 
        'then after pressing % button will display the % value
    End If

End Sub


Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bequal.Click



    Value2 = Val(TextBox1.Text)



    If Symbol = "+" Then

        Value3 = Value1 + Value2

    End If

    If Symbol = "-" Then

        Value3 = Value1 - Value2

    End If

    If Symbol = "*" Then


        Value3 = Value1 * Value2

    End If

    If Symbol = "/" Then


        Value3 = Value1 / Value2


    End If

    TextBox1.Text = " = " & Value3


    Valuex = Value3

    Symbol = "%"


End Sub

结束班

1 个答案:

答案 0 :(得分:0)

我的猜测是因为你在这些按钮的事件处理程序中有TextBox1.Text=""

看起来你可能已经从某个地方复制了一个例子。我建议你仔细阅读这些按钮的代码,如果你没有发现任何问题,设置一个断点并使用调试器来逐行观察它。