用vb编计算机 要求:一位数加减乘除,command1到9为数字,10是+,11是减,12是×,13是除。一段一段写,
作者:未知侠名时间:2022-11-27 06:47:42
command14是=,其他你写上对应字符就行
Private Sub Command1_Click()
Text1 = Text1 & Command1.Caption
End Sub
Private Sub Command2_Click()
Text1 = Text1 & Command2.Caption
End Sub
Private Sub Command3_Click()
Text1 = Text1 & Command3.Caption
End Sub
Private Sub Command4_Click()
Text1 = Text1 & Command4.Caption
End Sub
Private Sub Command5_Click()
Text1 = Text1 & Command5.Caption
End Sub
Private Sub Command6_Click()
Text1 = Text1 & Command6.Caption
End Sub
Private Sub Command7_Click()
Text1 = Text1 & Command7.Caption
End Sub
Private Sub Command8_Click()
Text1 = Text1 & Command8.Caption
End Sub
Private Sub Command9_Click()
Text1 = Text1 & Command9.Caption
End Sub
Private Sub Command10_Click()
Text1 = Text1 & Command10.Caption
End Sub
Private Sub Command111_Click()
Text1 = Text1 & Command11.Caption
End Sub
Private Sub Command12_Click()
Text1 = Text1 & Command12.Caption
End Sub
Private Sub Command13_Click()
Text1 = Text1 & Command13.Caption
End Sub
Private Sub Command14_Click()
Text1.Text = CalcStr(Text1.Text)
End Sub
Function CalcStr(StrNum As String) As Double
Dim x As Integer
Dim y As Integer
For i = 1 To Len(Text1.Text)
If IsNumeric(Mid(StrNum, i, 1)) = False Then
x = Left(StrNum, i - 1)
y = Mid(StrNum, i + 1)
z = Mid(StrNum, i, 1)
Exit For
End If
Next
Select Case z
Case "+"
CalcStr = x + y
Case "-"
CalcStr = x - y
Case "*"
CalcStr = x * y
Case "/"
If y = 0 Then
MsgBox "除数应不为0"
Else
CalcStr = x / y
End If
End Select
End Function 你好!
主要思路,如每一个按钮,
text1.text=text1.text & "1"
n=n+1 这个n 主要是为了,在最后计算结果用的
加号的是
text1.text=text1.text & "+"
后面的计算结果,就是
text1.text=text1.text & n
望采纳
记得给问豆啊! 百度看下
Private Sub Command1_Click()
Text1 = Text1 & Command1.Caption
End Sub
Private Sub Command2_Click()
Text1 = Text1 & Command2.Caption
End Sub
Private Sub Command3_Click()
Text1 = Text1 & Command3.Caption
End Sub
Private Sub Command4_Click()
Text1 = Text1 & Command4.Caption
End Sub
Private Sub Command5_Click()
Text1 = Text1 & Command5.Caption
End Sub
Private Sub Command6_Click()
Text1 = Text1 & Command6.Caption
End Sub
Private Sub Command7_Click()
Text1 = Text1 & Command7.Caption
End Sub
Private Sub Command8_Click()
Text1 = Text1 & Command8.Caption
End Sub
Private Sub Command9_Click()
Text1 = Text1 & Command9.Caption
End Sub
Private Sub Command10_Click()
Text1 = Text1 & Command10.Caption
End Sub
Private Sub Command111_Click()
Text1 = Text1 & Command11.Caption
End Sub
Private Sub Command12_Click()
Text1 = Text1 & Command12.Caption
End Sub
Private Sub Command13_Click()
Text1 = Text1 & Command13.Caption
End Sub
Private Sub Command14_Click()
Text1.Text = CalcStr(Text1.Text)
End Sub
Function CalcStr(StrNum As String) As Double
Dim x As Integer
Dim y As Integer
For i = 1 To Len(Text1.Text)
If IsNumeric(Mid(StrNum, i, 1)) = False Then
x = Left(StrNum, i - 1)
y = Mid(StrNum, i + 1)
z = Mid(StrNum, i, 1)
Exit For
End If
Next
Select Case z
Case "+"
CalcStr = x + y
Case "-"
CalcStr = x - y
Case "*"
CalcStr = x * y
Case "/"
If y = 0 Then
MsgBox "除数应不为0"
Else
CalcStr = x / y
End If
End Select
End Function 你好!
主要思路,如每一个按钮,
text1.text=text1.text & "1"
n=n+1 这个n 主要是为了,在最后计算结果用的
加号的是
text1.text=text1.text & "+"
后面的计算结果,就是
text1.text=text1.text & n
望采纳
记得给问豆啊! 百度看下
- 站长提醒大家:以上内容,未识真伪,仅供参考。理性上网,以免过度。谨慎广告,危及钱财。
版权声明:本信息由系统自动搜集网络信息,本站尊重网络信息的版权问题,本站所有内容仅供学习使用,版权归原作者所有,若有来源错误或者侵犯您的合法权益,您可通过邮箱与我们取得联系,我们将及时进行处理。