u011148571 于 2013.07.16 22:16 提问

vb代码实现计算器的小数点功能怎么实现，附代码，新手求解决？

Dim current As Double
Dim prev As Double
Dim choice As String
Dim temp As String
Dim PointFlag As Boolean ' 判断是否已有小数点

Private Sub ac_Click()
Text1.Text = ""
choice = "ac"
current = 0
End Sub

Private Sub asterisk_Click()
Text1.Text = ""
choice = "*"
prev = current
current = 0
End Sub

Private Sub Command0_Click()
current = current & "0"
Text1.Text = current
End Sub

Private Sub Command1_Click()
current = current & "1"
Text1.Text = current

``````End Sub
``````

Private Sub Command2_Click()
current = current & "2"
Text1.Text = current
End Sub

Private Sub Command3_Click()
current = current & "3"
Text1.Text = current
End Sub

Private Sub Command4_Click()
current = current & "4"
Text1.Text = current
End Sub

Private Sub Command5_Click()
current = current & "5"
Text1.Text = current
End Sub

Private Sub Command6_Click()
current = current & "6"
Text1.Text = current
End Sub

Private Sub Command7_Click()
current = current & "7"
Text1.Text = current
End Sub

Private Sub Command8_Click()
current = current & "8"
Text1.Text = current
End Sub

Private Sub Command9_Click()
current = current & "9"
Text1.Text = current
End Sub

Private Sub equal_Click()
If choice = "+" Then
current = prev + current
Text1.Text = current
ElseIf choice = "-" Then
current = prev - current
Text1.Text = current
ElseIf choice = "*" Then
current = prev * current
Text1.Text = current
ElseIf choice = "/" And current <> 0 Then
current = prev / current
Text1.Text = current
Else
Text1.Text = "Press AC to continue"
dz.Visible = True
dz.Caption = "Division by ZERO"
End If
If current < 0 Then
sroot.Enabled = False
Else
sroot.Enabled = True
End If

End Sub

PointFlag = False ' 将 PointFlag 设为否，即没有小数点。
End Sub

Private Sub minus_Click()
Text1.Text = ""
choice = "-"
prev = current
current = 0
End Sub

Private Sub plus_Click()
Text1.Text = ""
choice = "+"
prev = current
current = 0
End Sub

Private Sub point_Click()
End Sub

Private Sub sign_Click()
Text1.Text = -Val(Text1.Text)
current = Text1.Text
End Sub

Private Sub slash_Click()
Text1.Text = ""
choice = "/"
prev = current
current = 0
End Sub

Private Sub sroot_Click()
Text1.Text = Sqr(current)
current = Sqr(current)
End Sub

1个回答

wang0peng0hui0   2013.08.01 23:00