2 u011148571 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

Private Sub Form_Load()
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
wang0peng0hui0   2013.08.01 23:00

我前两天上传了一个计算器的源代码,自己编的,里面有小数点的功能实现,你可以看一下
http://download.csdn.net/detail/wang0peng0hui0/5835927

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!