Dim a As Integer
Dim b As Integer
a = Val(Mid(Text1Text, 1, 1))
b = Val(Mid(Text1Text, 3, 1))
Text1Text = a + b
Dim s1!, s2!, a$ '为小数点的叠加,s1,s2必须定义为单精度型
Dim flag As Boolean 'flag它是过程及的变量,在通用里必须声明
'在数字按钮控件单击数组单击事件中获取 *** 作数(没有区分是哪一个 *** 作数)
Private Sub Command1_Click(Index As Integer)
x = Text1Text
If flag = True Or x = "0" Then '查看数字是否输入完毕或者是否清零了
Text1Text = CStr(Index) 'CStr将数值转换字符
Else
Text1Text = Text1Text + CStr(Index) '"+"在这里这个是对字符串的 *** 作的叠加,CStr(Index)是接的数据
End If
flag = False '时刻准备数字的输入
End Sub
'2单击运算符,确定s1,并且要选定运算
Private Sub Command2_Click(Index As Integer)
flag = True
s1 = Val(Text1Text)
Select Case Index
Case 0
a = "+"
Case 1
a = "-"
Case 2
a = ""
Case 3
a = "/"
End Select
End Sub
'3"="的单击事件
Private Sub Command3_Click()
flag = True
s2 = Val(Text1Text)
Select Case a
Case "+"
Text1Text = s1 + s2
Case "-"
Text1Text = s1 - s2
Case ""
Text1Text = s1 s2
Case "/"
Text1Text = s1 / s2 '分母不能为0
End Select
s1 = 0: s2 = 0: a = ""
End Sub
'4清屏
Private Sub Command4_Click()
Text1Text = "0"
s1 = 0
s2 = 0
a = ""
flag = False
End Sub
'5删除最后输入的一个字符,换句话说,将本文框中的字符串取字符(从左往右取left(string,length)),将最后一个字符不取就先行
Private Sub Command5_Click()
If Text1Text = "" Then
Else
Command5Enabled = True
Text1Text = Left(Text1Text, Len(Text1Text) - 1)
'len求字符串的长度,left(text1len(text1)-1减1是取字符串从左往右减去一个字符串
End If
End Sub
'小数点 1)显示出""(注意前面输入过的整数必须显示) 2)小数后能继续接受数字的输入
Private Sub Command6_Click()
Text1 = Text1 & ""
End Sub
'7加入正负号--单击“+、-”,产生一个"-",而且处于一种等待数字输入的一种状态
Private Sub Command7_Click()
Dim temp As Double
temp = -Val(Text1Text)
Text1Text = temp
If d = " " Then s1 = temp Else s2 = temp
End Sub
Private Sub Command8_Click() '退出
End
End Sub
Private Sub Form_Load() '窗体初始化
Text1Text = 0
Text1Locked = True
End Sub
) 贴子相关: 界面可以到
中没显示结果显示在哪,我就将结果在text3中输出,具体代码如下,有疑问,可追问:
Private Sub Form_Load()
Combo1AddItem "+"
Combo1AddItem "-"
Combo1AddItem ""
Combo1AddItem "/"
End Sub
Private Sub Command1_Click()
If Combo1Text = "+" Then
Text3Text = Val(Text1Text) + Val(Text2Text)
ElseIf Combo1Text = "-" Then
Text3Text = Val(Text1Text) - Val(Text2Text)
ElseIf Combo1Text = "" Then
Text3Text = Val(Text1Text) Val(Text2Text)
ElseIf Combo1Text = "/" Then
If Text3Text = "0" Then
MsgBox "除数不能为0!"
Else
Text3Text = Val(Text1Text) / Val(Text2Text)
End If
End If
End Sub
Dim s1!, s2!, a$ '为小数点的叠加,s1,s2必须定义为单精度型
Dim flag As Boolean 'flag它是过程及的变量,在通用里必须声明
'在数字按钮控件单击数组单击事件中获取 *** 作数(没有区分是哪一个 *** 作数)
Private Sub Command1_Click(Index As Integer)
x = Text1Text
If flag = True Or x = "0" Then '查看数字是否输入完毕或者是否清零了
Text1Text = CStr(Index) 'CStr将数值转换字符
Else
Text1Text = Text1Text + CStr(Index) '"+"在这里这个是对字符串的 *** 作的叠加,CStr(Index)是接的数据
End If
flag = False '时刻准备数字的输入
End Sub
'2单击运算符,确定s1,并且要选定运算
Private Sub Command2_Click(Index As Integer)
flag = True
s1 = Val(Text1Text)
Select Case Index
Case 0
a = "+"
Case 1
a = "-"
Case 2
a = ""
Case 3
a = "/"
End Select
End Sub
'3"="的单击事件
Private Sub Command3_Click()
flag = True
s2 = Val(Text1Text)
Select Case a
Case "+"
Text1Text = s1 + s2
Case "-"
Text1Text = s1 - s2
Case ""
Text1Text = s1 s2
Case "/"
Text1Text = s1 / s2 '分母不能为0
End Select
s1 = 0: s2 = 0: a = ""
End Sub
'4清屏
Private Sub Command4_Click()
Text1Text = "0"
s1 = 0
s2 = 0
a = ""
flag = False
End Sub
'5删除最后输入的一个字符,换句话说,将本文框中的字符串取字符(从左往右取left(string,length)),将最后一个字符不取就先行
Private Sub Command5_Click()
If Text1Text = "" Then
Else
Command5Enabled = True
Text1Text = Left(Text1Text, Len(Text1Text) - 1)
'len求字符串的长度,left(text1len(text1)-1减1是取字符串从左往右减去一个字符串
End If
End Sub
'小数点 1)显示出""(注意前面输入过的整数必须显示) 2)小数后能继续接受数字的输入
Private Sub Command6_Click()
Text1 = Text1 & ""
End Sub
'7加入正负号--单击“+、-”,产生一个"-",而且处于一种等待数字输入的一种状态
Private Sub Command7_Click()
Dim temp As Double
temp = -Val(Text1Text)
Text1Text = temp
If d = " " Then s1 = temp Else s2 = temp
End Sub
Private Sub Command8_Click() '退出
End
End Sub
Private Sub Form_Load() '窗体初始化
Text1Text = 0
Text1Locked = True
End Sub
以上就是关于VB中如何在一个文本框中实现任意的四则运算(以加法为例)全部的内容,包括:VB中如何在一个文本框中实现任意的四则运算(以加法为例)、求VB程序代码(小学生四则运算题)、怎么用VB编写四则运算计算器等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)