关于计算器的问题
时间:2011-12-22
来源:互联网
[code=VB][/code]
Dim num1, t, d, cat, a
Private Sub Command1_Click(Index As Integer)
If Index <= 9 Then
If t > 9 And t <> 15 Then
Text1.Text = Index
Else
If Text1.Text = "0" Then
Text1.Text = Index
Else
Text1.Text = Text1.Text & Index
End If
End If
Else
Select Case Index
Case 10 '加法
If cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
End If
cat = 1
p = 0
Case 11 '减法
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
End If
cat = 2
p = 0
Case 12 '乘法
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
End If
cat = 3
p = 0
Case 13 '除法
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
End If
cat = 4
p = 0
Case 15 '小数点
If p = 0 Then
Text1.Text = Text1.Text + "."
p = 1
End If
Case 16 '等于
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
End If
p = 0
End Select
End If
t = Index
End Sub
Private Sub Command2_Click()
a = Len(Text1.Text)
If a = 1 Then
Text1.Text = 0
Else
Text1.Text = Left(Text1.Text, a - 1)
End If
End Sub
Private Sub Command3_Click()
Text1.Text = 0
num1 = 0
d = 0
p = 0
End Sub
Private Sub Form_Load()
d = 0
End Sub
Dim num1, t, d, cat, a
Private Sub Command1_Click(Index As Integer)
If Index <= 9 Then
If t > 9 And t <> 15 Then
Text1.Text = Index
Else
If Text1.Text = "0" Then
Text1.Text = Index
Else
Text1.Text = Text1.Text & Index
End If
End If
Else
Select Case Index
Case 10 '加法
If cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
End If
cat = 1
p = 0
Case 11 '减法
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
End If
cat = 2
p = 0
Case 12 '乘法
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
End If
cat = 3
p = 0
Case 13 '除法
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 * Val(Text1.Text)
Text1.Text = num1
ElseIf d = 0 Then
d = 1
num1 = Text1.Text
Text1.Text = 0
Else
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
End If
cat = 4
p = 0
Case 15 '小数点
If p = 0 Then
Text1.Text = Text1.Text + "."
p = 1
End If
Case 16 '等于
If cat = 1 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 3 Then
num1 = num1 + Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 2 Then
num1 = num1 - Val(Text1.Text)
Text1.Text = num1
ElseIf cat = 4 Then
num1 = num1 / Val(Text1.Text)
Text1.Text = num1
End If
p = 0
End Select
End If
t = Index
End Sub
Private Sub Command2_Click()
a = Len(Text1.Text)
If a = 1 Then
Text1.Text = 0
Else
Text1.Text = Left(Text1.Text, a - 1)
End If
End Sub
Private Sub Command3_Click()
Text1.Text = 0
num1 = 0
d = 0
p = 0
End Sub
Private Sub Form_Load()
d = 0
End Sub
作者: a52268968 发布时间: 2011-12-22
我想在点击一次小数点以后 删除小数点 能继续点出小数点 而只能有1个 。 跪求指导哇
作者: a52268968 发布时间: 2011-12-22
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28