vb编程,用select case 10
编一模拟袖珍计算器(四则运算即+、-、*、/)的完整程序,界面如图3-4所示。要求:输入两个操作数和一个操作符,根据操作符单击“计算”按钮进行计算。输入、输出数据均存放于...
编一模拟袖珍计算器(四则运算即+、-、*、/)的完整程序,界面如图3-4所示。要求:输入两个操作数和一个操作符,根据操作符单击“计算”按钮进行计算。输入、输出数据均存放于文本框中,窗体中所有控件字体默认、大小为小四。使用Select Case语句实现
急切啊!! 展开
急切啊!! 展开
2个回答
展开全部
Dim a As Double, b As Double, c As String
Private Sub Command1_Click()
Text1.Text = Text1.Text & "1"
End Sub
Private Sub Command10_Click()
Text1.Text = Text1.Text & "9"
End Sub
Private Sub Command11_Click()
Text1.Text = Text1.Text & "8"
End Sub
Private Sub Command12_Click()
Text1.Text = Text1.Text & "7"
End Sub
Private Sub Command13_Click()
Text1.Text = Text1.Text & "6"
End Sub
Private Sub Command14_Click()
Text1.Text = Text1.Text & "5"
End Sub
Private Sub Command15_Click()
Text1.Text = Text1.Text & "4"
End Sub
Private Sub Command16_Click()
Text1.Text = Text1.Text & "3"
End Sub
Private Sub Command17_Click()
Text1.Text = Text1.Text & "2"
End Sub
Private Sub Command2_Click()’清空
Text1.Text = ""
Text1.SetFocus
End Sub
Dim i As Variant
If Text1.Text = "" Then Exit Sub
aa = Len(Text1.Text)
If Text1.Text <> "" Then
For i = 1 To aa
If Asc(Mid(Text1.Text, i, 1)) < 46 Or Asc(Mid(Text1.Text, i, 1)) > 57 Or Asc(Mid(Text1.Text, i, 1)) = 47 Then
MsgBox "非法数据,请重新输入!", 64, "提示!"
Text1.Text = ""
Text1.SetFocus
Exit For
End If
Next i
End If
b = Val(Text1.Text)
Select Case c
Case "+"
Text1.Text = Val(a) + Val(b)
Case "-"
Text1.Text = Val(a) - Val(b)
Case "*"
If b = "0" Or a = "0" Then
MsgBox "0不可以其它数相乘,请输入正确的数据!", 16, "提示!"
Text1.Text = ""
Text1.SetFocus
Exit Sub
End If
Text1.Text = Val(a) * Val(b)
Case "/"
If Val(b) = 0 Then Exit Sub
If a = 0 Or b = 0 Then
MsgBox "0不可以作除数,请输入正确的数据!", 16, "提示!"
Text1.Text = ""
Text1.SetFocus
Exit Sub
End If
Text1.Text = Val(a) / Val(b)
End Select
If IsNumeric(Text1.Text) Then
Text1.Text = Text1.Text
End If
End Sub
Private Sub Command4_Click()
If Text1.Text = "" Then Exit Sub
a = Text1.Text
Text1.Text = ""
c = "/"
End Sub
Private Sub Command5_Click()
If Text1.Text = "" Then Exit Sub
a = Text1.Text
Text1.Text = ""
c = "-"
End Sub
Private Sub Command6_Click()
If Text1.Text = "" Then Exit Sub
a = Text1.Text
Text1.Text = ""
c = "*"
End Sub
Private Sub Command7_Click()
If Text1.Text = "" Then Exit Sub
a = Text1.Text
Text1.Text = ""
c = "+"
End Sub
Private Sub Command8_Click()
If InStr(1, Text1.Text, ".") > 0 Then Exit Sub
If Len(Text1.Text) = 0 Then Text1.Text = "0"
Text1.Text = Text1.Text & "."
End Sub
Private Sub Command9_Click()
Text1.Text = Text1.Text & "0"
End Sub
Private Sub Form_Load()
Text1.fontsize = 40
End Sub
Private Sub Text1_Change()
If KeyAscii = 46 Then
If InStr(1, Text1.Text, ".") > 0 Then
KeyAscii = 0: Exit Sub
Else
Exit Sub
End If
End If
If KeyAscii >= 48 And KeyAscii <= 57 Then Exit Sub
If KeyAscii = 8 Or KeyAscii = 13 Then Exit Sub
If KeyAscii = 45 Then Exit Sub
KeyAscii = 0
End Sub
Private Sub Command1_Click()
Text1.Text = Text1.Text & "1"
End Sub
Private Sub Command10_Click()
Text1.Text = Text1.Text & "9"
End Sub
Private Sub Command11_Click()
Text1.Text = Text1.Text & "8"
End Sub
Private Sub Command12_Click()
Text1.Text = Text1.Text & "7"
End Sub
Private Sub Command13_Click()
Text1.Text = Text1.Text & "6"
End Sub
Private Sub Command14_Click()
Text1.Text = Text1.Text & "5"
End Sub
Private Sub Command15_Click()
Text1.Text = Text1.Text & "4"
End Sub
Private Sub Command16_Click()
Text1.Text = Text1.Text & "3"
End Sub
Private Sub Command17_Click()
Text1.Text = Text1.Text & "2"
End Sub
Private Sub Command2_Click()’清空
Text1.Text = ""
Text1.SetFocus
End Sub
Dim i As Variant
If Text1.Text = "" Then Exit Sub
aa = Len(Text1.Text)
If Text1.Text <> "" Then
For i = 1 To aa
If Asc(Mid(Text1.Text, i, 1)) < 46 Or Asc(Mid(Text1.Text, i, 1)) > 57 Or Asc(Mid(Text1.Text, i, 1)) = 47 Then
MsgBox "非法数据,请重新输入!", 64, "提示!"
Text1.Text = ""
Text1.SetFocus
Exit For
End If
Next i
End If
b = Val(Text1.Text)
Select Case c
Case "+"
Text1.Text = Val(a) + Val(b)
Case "-"
Text1.Text = Val(a) - Val(b)
Case "*"
If b = "0" Or a = "0" Then
MsgBox "0不可以其它数相乘,请输入正确的数据!", 16, "提示!"
Text1.Text = ""
Text1.SetFocus
Exit Sub
End If
Text1.Text = Val(a) * Val(b)
Case "/"
If Val(b) = 0 Then Exit Sub
If a = 0 Or b = 0 Then
MsgBox "0不可以作除数,请输入正确的数据!", 16, "提示!"
Text1.Text = ""
Text1.SetFocus
Exit Sub
End If
Text1.Text = Val(a) / Val(b)
End Select
If IsNumeric(Text1.Text) Then
Text1.Text = Text1.Text
End If
End Sub
Private Sub Command4_Click()
If Text1.Text = "" Then Exit Sub
a = Text1.Text
Text1.Text = ""
c = "/"
End Sub
Private Sub Command5_Click()
If Text1.Text = "" Then Exit Sub
a = Text1.Text
Text1.Text = ""
c = "-"
End Sub
Private Sub Command6_Click()
If Text1.Text = "" Then Exit Sub
a = Text1.Text
Text1.Text = ""
c = "*"
End Sub
Private Sub Command7_Click()
If Text1.Text = "" Then Exit Sub
a = Text1.Text
Text1.Text = ""
c = "+"
End Sub
Private Sub Command8_Click()
If InStr(1, Text1.Text, ".") > 0 Then Exit Sub
If Len(Text1.Text) = 0 Then Text1.Text = "0"
Text1.Text = Text1.Text & "."
End Sub
Private Sub Command9_Click()
Text1.Text = Text1.Text & "0"
End Sub
Private Sub Form_Load()
Text1.fontsize = 40
End Sub
Private Sub Text1_Change()
If KeyAscii = 46 Then
If InStr(1, Text1.Text, ".") > 0 Then
KeyAscii = 0: Exit Sub
Else
Exit Sub
End If
End If
If KeyAscii >= 48 And KeyAscii <= 57 Then Exit Sub
If KeyAscii = 8 Or KeyAscii = 13 Then Exit Sub
If KeyAscii = 45 Then Exit Sub
KeyAscii = 0
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没看到图 传图上来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |