懂VB的进来,这个是个计算器的代码,但是计算的时候,0.8除以2就是0.5.0.2除以2就是0.等于说是四舍五入Dim IntNum As IntegerDim LonNum As LongDim IntNum2 As IntegerPrivate Sub Command1_Click()If IntNum2 = 1 ThenText1.Text =
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/30 11:54:49
懂VB的进来,这个是个计算器的代码,但是计算的时候,0.8除以2就是0.5.0.2除以2就是0.等于说是四舍五入Dim IntNum As IntegerDim LonNum As LongDim IntNum2 As IntegerPrivate Sub Command1_Click()If IntNum2 = 1 ThenText1.Text =
懂VB的进来,这个是个计算器的代码,但是计算的时候,0.8除以2就是0.5.0.2除以2就是0.等于说是四舍五入
Dim IntNum As Integer
Dim LonNum As Long
Dim IntNum2 As Integer
Private Sub Command1_Click()
If IntNum2 = 1 Then
Text1.Text = 1
IntNum2 = 0
Else
Text1.Text = Text1.Text & 1
End If
End Sub
Private Sub Command10_Click()
If IntNum2 = 1 Then
Text1.Text = 6
IntNum2 = 0
Else
Text1.Text = Text1.Text & 6
End If
End Sub
Private Sub Command11_Click()
If IntNum2 = 1 Then
Text1.Text = 9
IntNum2 = 0
Else
Text1.Text = Text1.Text & 9
End If
End Sub
Private Sub Command12_Click()
LonNum = Text1.Text
IntNum = 4
Text1.Text = ""
End Sub
Private Sub Command13_Click()
LonNum = Text1.Text
IntNum = 1
Text1.Text = ""
End Sub
Private Sub Command14_Click()
LonNum = Text1.Text
IntNum = 2
Text1.Text = ""
End Sub
Private Sub Command15_Click()
LonNum = Text1.Text
IntNum = 3
Text1.Text = ""
End Sub
Private Sub Command16_Click()
If IntNum = 1 Then
Text1.Text = LonNum + Text1.Text
ElseIf IntNum = 2 Then
Text1.Text = LonNum - Text1.Text
ElseIf IntNum = 3 Then
Text1.Text = LonNum * Text1.Text
ElseIf IntNum = 4 Then
If Text1.Text = 0 Then
Ret = MsgBox("除数不能为0",32 + 3,"错误")
Else
Text1.Text = LonNum / Text1.Text
End If
End If
IntNum2 = 1
End Sub
Private Sub Command17_Click()
Text1.Text = ""
End Sub
Private Sub Command2_Click()
If IntNum2 = 1 Then
Text1.Text = 4
IntNum2 = 0
Else
Text1.Text = Text1.Text & 4
End If
End Sub
Private Sub Command3_Click()
If IntNum2 = 1 Then
Text1.Text = 7
IntNum2 = 0
Else
Text1.Text = Text1.Text & 7
End If
End Sub
Private Sub Command4_Click()
If IntNum2 = 1 Then
Text1.Text = "."
IntNum2 = 0
Else
Text1.Text = Text1.Text & "."
End If
End Sub
Private Sub Command5_Click()
If IntNum2 = 1 Then
Text1.Text = 2
IntNum2 = 0
Else
Text1.Text = Text1.Text & 2
End If
End Sub
Private Sub Command6_Click()
If IntNum2 = 1 Then
Text1.Text = 5
IntNum2 = 0
Else
Text1.Text = Text1.Text & 5
End If
End Sub
Private Sub Command7_Click()
If IntNum2 = 1 Then
Text1.Text = 8
IntNum2 = 0
Else
Text1.Text = Text1.Text & 8
End If
End Sub
Private Sub Command8_Click()
If IntNum2 = 1 Then
Text1.Text = 0
IntNum2 = 0
Else
Text1.Text = Text1.Text & 0
End If
End Sub
Private Sub Command9_Click()
If IntNum2 = 1 Then
Text1.Text = 3
IntNum2 = 0
Else
Text1.Text = Text1.Text & 3
End If
End Sub
懂VB的进来,这个是个计算器的代码,但是计算的时候,0.8除以2就是0.5.0.2除以2就是0.等于说是四舍五入Dim IntNum As IntegerDim LonNum As LongDim IntNum2 As IntegerPrivate Sub Command1_Click()If IntNum2 = 1 ThenText1.Text =
由于你声明的变量都是整数,所以VB在赋值时会先进行取整,比如在Text1输入0.8,则
LonNum = Text1.Text = 0.8 转为整数就是1
再把1除以2不就是0.5吗?
同理,输入0.2则VB会自动转为0,然后0除以2不就是0吗?
应该把变量声明为浮点数(Single或Double)