2017年10月26日 星期四

VB 計算機




Public Class Form1
    Dim tmp As Double = 0
    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
        TextBox1.ReadOnly = True
        Label2.Text = tmp
        Label3.Text = ""
    End Sub

    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ 
Handles btn1.Click
        TextBox1.Text += btn1.Text
    End Sub

    Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)_
 Handles btn2.Click
        TextBox1.Text += btn2.Text
    End Sub

    Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)_
Handles btn3.Click
        TextBox1.Text += btn3.Text
    End Sub

    Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn4.Click
        TextBox1.Text += btn4.Text
    End Sub

    Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn5.Click
        TextBox1.Text += btn5.Text
    End Sub

    Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn6.Click
        TextBox1.Text += btn6.Text
    End Sub

    Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  Handles btn7.Click
        TextBox1.Text += btn7.Text
    End Sub

    Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn8.Click
        TextBox1.Text += btn8.Text
    End Sub

    Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn9.Click
        TextBox1.Text += btn9.Text
    End Sub

    Private Sub btnplus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnplus.Click
        If CDbl(Label2.Text) = 0 Then
            Label2.Text = TextBox1.Text
            Label3.Text = "+"
            TextBox1.Text = ""
        ElseIf Label3.Text = "-" Then
            Label2.Text = CDbl(Label2.Text) - CDbl(TextBox1.Text)
            Label3.Text = "+"
            TextBox1.Text = ""
        ElseIf Label3.Text = "*" Then
            Label2.Text = CDbl(Label2.Text) * CDbl(TextBox1.Text)
            Label3.Text = "+"
            TextBox1.Text = ""
        ElseIf Label3.Text = "/" Then
            Label2.Text = CDbl(Label2.Text) / CDbl(TextBox1.Text)
            Label3.Text = "+"
            TextBox1.Text = ""
        Else
            Label2.Text = CDbl(Label2.Text) + CDbl(TextBox1.Text)
            Label3.Text = "+"
            TextBox1.Text = ""
        End If
    End Sub

    Private Sub btnequ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)_
 Handles btnequ.Click
        If TextBox1.Text = "" Then
            TextBox1.Text = Label2.Text
            Exit Sub
        End If
        Select Case Label3.Text
            Case "+"
                TextBox1.Text += CDbl(Label2.Text)
            Case "-"
                TextBox1.Text = CDbl(Label2.Text) - CDbl(TextBox1.Text)
            Case "*"
                TextBox1.Text = CDbl(Label2.Text) * CDbl(TextBox1.Text)
            Case "/"
                TextBox1.Text = CDbl(Label2.Text) / CDbl(TextBox1.Text)
        End Select
    End Sub

    Private Sub btnsub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)_
 Handles btnsub.Click
        If CDbl(Label2.Text) = 0 Then
            Label2.Text = TextBox1.Text
            Label3.Text = "-"
            TextBox1.Text = ""
        ElseIf Label3.Text = "+" Then
            Label2.Text += CDbl(TextBox1.Text)
            TextBox1.Text = ""
            Label3.Text = "-"
        ElseIf Label3.Text = "*" Then
            Label2.Text *= CDbl(TextBox1.Text)
            TextBox1.Text = ""
            Label3.Text = "-"
        ElseIf Label3.Text = "/" Then
            Label2.Text = CDbl(Label2.Text) / CDbl(TextBox1.Text)
            Label3.Text = "-"
            TextBox1.Text = ""
        Else
            Label2.Text = CDbl(Label2.Text) - CDbl(TextBox1.Text)
            Label3.Text = "-"
            TextBox1.Text = ""
        End If
    End Sub

    Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)_
 Handles btnexit.Click
        Application.Exit()
    End Sub

    Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn0.Click
        TextBox1.Text += btn0.Text
    End Sub

    Private Sub btnmul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)_
 Handles btnmul.Click
        If CDbl(Label2.Text) = 0 Then
            Label2.Text = TextBox1.Text
            Label3.Text = "*"
            TextBox1.Text = ""
        ElseIf Label3.Text = "+" Then
            Label2.Text += CDbl(TextBox1.Text)
            Label3.Text = "*"
            TextBox1.Text = ""
        ElseIf Label3.Text = "-" Then
            Label2.Text = CDbl(Label2.Text) - CDbl(TextBox1.Text)
            Label3.Text = "*"
            TextBox1.Text = ""
        ElseIf Label3.Text = "/" Then
            Label2.Text = CDbl(Label2.Text) / CDbl(TextBox1.Text)
            Label3.Text = "*"
            TextBox1.Text = ""
        Else
            Label2.Text = CDbl(Label2.Text) * CDbl(TextBox1.Text)
            Label3.Text = "*"
            TextBox1.Text = ""
        End If
    End Sub

    Private Sub btndiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles btndiv.Click
        If CDbl(Label2.Text) = 0 Then
            Label2.Text = TextBox1.Text
            Label3.Text = "/"
            TextBox1.Text = ""
        ElseIf Label3.Text = "+" Then
            Label2.Text += CDbl(TextBox1.Text)
            Label3.Text = "/"
            TextBox1.Text = ""
        ElseIf Label3.Text = "-" Then
            Label2.Text = CDbl(Label2.Text) - CDbl(TextBox1.Text)
            Label3.Text = "/"
            TextBox1.Text = ""
        ElseIf Label3.Text = "*" Then
            Label2.Text = CDbl(Label2.Text) * CDbl(TextBox1.Text)
            Label3.Text = "*"
            TextBox1.Text = ""
        Else
            Label2.Text = CDbl(Label2.Text) / CDbl(TextBox1.Text)
            Label3.Text = "/"
            TextBox1.Text = ""
        End If
    End Sub

    Private Sub reset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles reset.Click
        Label2.Text = 0
        Label3.Text = ""
        TextBox1.Text = ""
    End Sub

    Private Sub btndot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btndot.Click
        TextBox1.Text += btndot.Text
    End Sub
End Class


修改成如下的畫面


沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...