用vb语言编写一个简易计算器
发布网友
发布时间:2023-01-31 23:03
我来回答
共2个回答
热心网友
时间:2023-05-18 06:28
Dim N1 As Single
Dim ysf As String
Dim qing As Boolean
Dim M As Single
Private Sub C_Click(Index As Integer)
If qing = True Then
L.Caption = ""
qing = False
End If
L.Caption = L.Caption & C(Index).Caption
End Sub
Private Sub Command1_Click()
qing = True
Dim N2 As Single
Dim T As Single
N2 = Val(L.Caption)
Select Case ysf
Case "+"
T = N1 + N2
Case "-"
T = N1 - N2
Case "*"
T = N1 * N2
Case "/"
T = N1 / N2
End Select
L.Caption = T
End Sub
Private Sub Command10_Click()
M = Val(L.Caption)
L1.Caption = "M"
End Sub
Private Sub Command11_Click()
M = M + Val(L.Caption)
End Sub
Private Sub Command2_Click()
L.Caption = -Val(L.Caption)
End Sub
Private Sub Command3_Click()
If L.Caption <> "" Then
L.Caption = Left(L.Caption, Len(L.Caption) - 1)
End If
End Sub
Private Sub Command4_Click()
N1 = 0
L.Caption = ""
ysf = "+"
End Sub
Private Sub Command5_Click()
L.Caption = ""
End Sub
Private Sub Command6_Click()
L.Caption = Sqr(Val(L.Caption))
qing = True
End Sub
Private Sub Command7_Click()
L.Caption = 1 / (Val(L.Caption))
End Sub
Private Sub Command8_Click()
M = 0
L1.Caption = ""
End Sub
Private Sub Command9_Click()
L.Caption = M
End Sub
Private Sub Form_Load()
ysf = "+"
End Sub
Private Sub s_Click(Index As Integer)
N1 = L.Caption
ysf = s(Index).Caption
qing = True
End Sub
Private Sub xsd_Click()
If qing = True Then
L.Caption = ""
qing = False
End If
If InStr(1, L.Caption, ".") = 0 Then
L.Caption = L.Caption & "."
End If
End Sub
热心网友
时间:2023-05-18 06:28
http://hi.baidu.com/flyhoney860615/blog/item/e2859ed61231112f07088b39.html