VB计算器添加了一些功能

时间:2020-02-14 07:21:24

标签: vb.net winforms calculator

我已经用Visual Basic编写了一个计算器,但是我想添加更多功能。但是我无法弄清楚如何在我的代码中解决以下问题:

  1. 如果在输入字段中输入多个零,则只需删除前导零(例如0000111 -----> 111或0002345 ----> 2345)

    < / li>
  2. 同样,十进制数字在小数点前不应有多个零(例如000.176 ----> 0.176)

  3. 此外,应该不能输入两个逗号(示例0.187.56 ----->不可能是-------------> 0.18756) 有人可以帮我吗?

Public Class Form1
    Public LCD As Single
    Public OPZ As String

    Private Sub LCDfuellen(sender As Object, e As EventArgs) Handles btn3.Click, btn2.Click, btn1.Click, btn9.Click, btn8.Click, btn7.Click, btn6.Click, btn5.Click, btn4.Click
        txtLCD.Text &= ActiveControl.Tag

        Replace(LTrim(Replace(txtLCD.Text, "0", " ")), " ", "0")

    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        txtLCD.Clear()
    End Sub

    Private Sub btnCE_Click(sender As Object, e As EventArgs) Handles btnCE.Click
        'txtLCD.Text = txtLCD.Text.Remove(txtLCD.TextLength - 1, 1)
        txtLCD.Text = LSet(txtLCD.Text, txtLCD.TextLength - 1)
    End Sub

    Private Sub OPZlesen(sender As Object, e As EventArgs) Handles btnPlus.Click, btnMinus.Click, btnMal.Click, btnDurch.Click
        LCD = CSng(txtLCD.Text)
        txtLCD.Clear()
        OPZ = ActiveControl.Tag



    End Sub

    Private Sub btnGleich_Click(sender As Object, e As EventArgs) Handles btnGleich.Click
        Dim activeLCD As Single
        activeLCD = CSng(txtLCD.Text)

        Select Case OPZ
            Case "+" : txtLCD.Text = CStr(LCD + activeLCD)
            Case "-" : txtLCD.Text = CStr(LCD - activeLCD)
            Case "*" : txtLCD.Text = CStr(LCD * activeLCD)
            Case "/" : txtLCD.Text = CStr(LCD / activeLCD)
        End Select
    End Sub



    Private Sub btn0_Click(sender As Object, e As EventArgs) Handles btn0.Click

        txtLCD.Text &= ActiveControl.Tag

    End Sub

    Private Sub btnPunkt_Click(sender As Object, e As EventArgs) Handles btnPunkt.Click

        txtLCD.Text &= ActiveControl.Tag
    End Sub


End Class


0 个答案:

没有答案