用VB寫計算器

qkoqhh發表於2017-10-03

我是沒什麼心思寫計算器的。。不過要參加星火盃的話這個坎還是要過一過。。。

emmmm然後發現寫個GUI真是步步艱難,先用了VS發現特麼廢流量,再用QT一直蜜汁錯誤。。然後。。然後最終還是向VB低頭orz

演算法上不存在什麼問題啦。。只是不熟悉而且很多細節需要注意。。debug幾下就好。。最重要的是學到了用程式寫程式的姿勢_(:з」∠)_

一個不能再簡單的視窗

還有一段又臭又長的程式碼

Dim t, t1 As Integer
Dim x, y As Double


Public Sub com()
x = Val(l1.Caption)
Select Case t1
Case Is = 1: y = y + x
Case Is = 2: y = y - x
Case Is = 3: y = y * x
Case Is = 4: y = y / x
End Select
t1 = 0
t = 0
l1.Caption = "0"
End Sub


Private Sub Form_Load()
x = 0
y = 0
t = 0
t1 = 1
End Sub






Private Sub c0_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "0"
Else
l1.Caption = l1.Caption + "0"
End If
End Sub

Private Sub C1_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "1"
Else
l1.Caption = l1.Caption + "1"
End If

End Sub
Private Sub c10_Click(Index As Integer)
    If t = 0 Then
    l1.Caption = l1.Caption + "."
    t = 1
    End If
End Sub

Private Sub C2_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "2"
Else
l1.Caption = l1.Caption + "2"
End If

End Sub

Private Sub C3_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "3"
Else
l1.Caption = l1.Caption + "3"
End If

End Sub

Private Sub C4_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "4"
Else
l1.Caption = l1.Caption + "4"
End If

End Sub

Private Sub C5_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "5"
Else
l1.Caption = l1.Caption + "5"
End If

End Sub

Private Sub C6_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "6"
Else
l1.Caption = l1.Caption + "6"
End If

End Sub

Private Sub C7_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "7"
Else
l1.Caption = l1.Caption + "7"
End If

End Sub

Private Sub C8_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "8"
Else
l1.Caption = l1.Caption + "8"
End If

End Sub

Private Sub C9_Click(Index As Integer)
If l1.Caption = "0" Then
l1.Caption = "9"
Else
l1.Caption = l1.Caption + "9"
End If

End Sub












Private Sub z1_Click(Index As Integer)
com
t1 = 1
End Sub

Private Sub z2_Click(Index As Integer)
com
t1 = 2
End Sub

Private Sub z3_Click(Index As Integer)
com
t1 = 3
End Sub

Private Sub z4_Click(Index As Integer)
com
t1 = 4
End Sub

Private Sub z5_Click(Index As Integer)
tmp = Mid(l1.Caption, Len(l1.Caption), 1)
If tmp = "." Then
t = 0
End If
If Len(l1.Caption) = 1 Then
l1.Caption = "0"
Else
l1.Caption = Left(l1.Caption, Len(l1.Caption) - 1)
End If
End Sub

Private Sub z6_Click(Index As Integer)
l1.Caption = "0"
Form_Load
End Sub

Private Sub z7_Click(Index As Integer)
If (l1.Caption <> "0") Then
l1.Caption = "-" + l1.Caption
End If
End Sub

Private Sub z8_Click(Index As Integer)
com
l1.Caption = Str(y)
End Sub


相關文章