用VB写计算器

我是没什么心思写计算器的。。不过要参加星火杯的话这个坎还是要过一过。。。

emmmm然后发现写个GUI真是步步艰难,先用了VS发现特么废流量,再用QT一直蜜汁错误。。然后。。然后最终还是向VB低头orz

算法上不存在什么问题啦。。只是不熟悉而且很多细节需要注意。。debug几下就好。。最重要的是学到了用程序写程序的姿势_(:з」∠)_

一个不能再简单的窗口

用VB写计算器_第1张图片

还有一段又臭又长的代码

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


你可能感兴趣的:(非算法类)