硬币反面英语:初学vb,计算器小数点出现问题.不能解决累加.高手进来帮帮忙

来源:百度文库 编辑:高考问答 时间:2024/04/29 06:04:05
高手帮改一改.我实现不聊小数点,累加,和"0"可以一直出现..

============================================================
Dim PointFlag As Boolean
Dim num1 As Single '操作数
Dim num2 As Single '操作数
Dim flag As Boolean '逻辑变量辨别运算符
Dim op As String '储存运算符
Dim result As Single '储存运算结果
Dim OffSign As Boolean '计算器关闭标志

Private Sub clear_Click()
num1 = 0
num2 = 0
op = ""
result = 0
Text1.Text = "0."
flag = False
PointFlag = False
End Sub

Private Sub Command1_Click()
If OffSign = False Then

If Index = 16 Then
Else
End If
End If
End Sub

Private Sub DecimalFlag_Click()
Select Case "."
Case "."
If Not PointFlag Then
If FirstN Then '
Text1.Text = "0."
flag = False
Else
op = op + "."
End If
Else
Exit Sub
End If
End Select
PointFlag = True ' 将小数点标志为真,即在输入串中有了小数点
Text1.Text = num1

End Sub

Private Sub equal_Click()
Select Case op
Case "+"
result = num1 + num2
Case "-"
result = num1 - num2
Case "*"
result = num1 * num2
Case "/"
If num2 = 0 Then
MsgBox "除数不能为零", 48, "计算器"
Else
result = num1 / num2
End If

End Select
Text1.Text = result
num1 = result
num2 = 0
End Sub

Private Sub number_Click(Index As Integer)
Text1.Text = Text1.Text & number(Index).Caption
If flag <> True Then
num1 = Val(Text1.Text)
Else
num2 = Val(Text1.Text)
End If

End Sub

Private Sub operator_Click(Index As Integer)
op = operator(Index).Caption
Text1.Text = ""
flag = True
End Sub

Private Sub over_Click(Index As Integer)
Select Case Index
Case 0
OffSign = False
Text1.Text = "0."
over(0).Enabled = False
over(1).Enabled = True
Case 1
OffSign = True
Text1.Text = ""
FirstNum = True
over(1).Enabled = False
over(0).Enabled = True
End Select

End Sub

========================================================

Private Sub DecimalFlag_Click()
If Not PointFlag Then
If FirstN Then
Text1.Text = "0."
PointFlag = True
End If
End If
If flag <> True Then
num1 = Val(Text1.Text)
Else
num2 = Val(Text1.Text)
End If
End Sub

Private Sub equal_Click()
Select Case op
Case "+"
result = num1 + num2
Case "-"
result = num1 - num2
Case "*"
result = num1 * num2
Case "/"
If num2 = 0 Then
MsgBox "除数不能为零", 48, "计算器"
Else
result = num1 / num2
End If
End Select
Text1.Text = result
num1 = result
num2 = 0
flag = False '重设标志
End Sub

Private Sub operator_Click(Index As Integer)
op = operator(Index).Caption
Text1.Text = ""
flag = True
PointFlag = False '重设小数标志
End Sub
========================================================

不知道这样行不行。