VB6文本框内自动加法运算
2个回答
展开全部
比较简单的是建立3个textbox,text1、text2、和text3,text3用来显示text1和text2的运算结果!
在你要处理的运算符加入下面相对应的代码!
text3.text = val(text1.text) + val(text2.text) '加法运算
text3.text = val(text1.text) - val(text2.text) '减法运算
text3.text = val(text1.text) * val(text2.text) '乘法运算
text3.text = val(text1.text) / val(text2.text) '除法运算
在你要处理的运算符加入下面相对应的代码!
text3.text = val(text1.text) + val(text2.text) '加法运算
text3.text = val(text1.text) - val(text2.text) '减法运算
text3.text = val(text1.text) * val(text2.text) '乘法运算
text3.text = val(text1.text) / val(text2.text) '除法运算
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
急也不加点分,
Private Sub XX()
On Error GoTo Wro:
Dim a As Integer, b As Integer
For i = 1 To Len(Text1.Text)
Select Case Mid(Text1.Text, i, 1)
Case "+"
a = i
b = 1
Case "-"
a = i
b = 2
Case "*"
a = i
b = 3
Case "/"
a = i
b = 4
End Select
Next
If IsNumeric(Left(Text1.Text, a - 1)) = True And IsNumeric(Right(Text1.Text, Len(Text1.Text) - a)) = True Then
Select Case b
Case 1
Text1.Text = Text1.Text & "=" & CSng(Left(Text1.Text, a - 1)) + CSng(Right(Text1.Text, Len(Text1.Text) - a))
Case 2
Text1.Text = Text1.Text & "=" & CSng(Left(Text1.Text, a - 1)) - CSng(Right(Text1.Text, Len(Text1.Text) - a))
Case 3
Text1.Text = Text1.Text & "=" & CSng(Left(Text1.Text, a - 1)) * CSng(Right(Text1.Text, Len(Text1.Text) - a))
Case 4
Text1.Text = Text1.Text & "=" & CSng(Left(Text1.Text, a - 1)) / CSng(Right(Text1.Text, Len(Text1.Text) - a))
End Select
End If
Exit Sub
Wro:
End Sub
Private Sub form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X < Text1.Left Or X > (Text1.Left + Text1.Width) Or Y < Text1.Top Or Y > (Text1.Top + Text1.Height) Then XX
End Sub
Private Sub XX()
On Error GoTo Wro:
Dim a As Integer, b As Integer
For i = 1 To Len(Text1.Text)
Select Case Mid(Text1.Text, i, 1)
Case "+"
a = i
b = 1
Case "-"
a = i
b = 2
Case "*"
a = i
b = 3
Case "/"
a = i
b = 4
End Select
Next
If IsNumeric(Left(Text1.Text, a - 1)) = True And IsNumeric(Right(Text1.Text, Len(Text1.Text) - a)) = True Then
Select Case b
Case 1
Text1.Text = Text1.Text & "=" & CSng(Left(Text1.Text, a - 1)) + CSng(Right(Text1.Text, Len(Text1.Text) - a))
Case 2
Text1.Text = Text1.Text & "=" & CSng(Left(Text1.Text, a - 1)) - CSng(Right(Text1.Text, Len(Text1.Text) - a))
Case 3
Text1.Text = Text1.Text & "=" & CSng(Left(Text1.Text, a - 1)) * CSng(Right(Text1.Text, Len(Text1.Text) - a))
Case 4
Text1.Text = Text1.Text & "=" & CSng(Left(Text1.Text, a - 1)) / CSng(Right(Text1.Text, Len(Text1.Text) - a))
End Select
End If
Exit Sub
Wro:
End Sub
Private Sub form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X < Text1.Left Or X > (Text1.Left + Text1.Width) Or Y < Text1.Top Or Y > (Text1.Top + Text1.Height) Then XX
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询