vb高手,关于控件数组的问题
利用单选按钮控件数组,选择一种运算,我的代码不知道哪儿有问题,老提示溢出PrivateSubOption1_Click(IndexAsInteger)DimXAsStri...
利用单选按钮控件数组,选择一种运算,我的代码不知道哪儿有问题,老提示溢出
Private Sub Option1_Click(Index As Integer)
Dim X As String
Dim Y As String
X = Val(Text1.Text)
Y = Val(Text2.Text)
If Text1.Text <> "" & Text2.Text <> "" Then
Select Case Index
Case 0
Text3.Text = Y / X
Case 1
Text3.Text = Y \ X
Case 2
Text3.Text = Y Mod X
End If
End Select
End Sub 展开
Private Sub Option1_Click(Index As Integer)
Dim X As String
Dim Y As String
X = Val(Text1.Text)
Y = Val(Text2.Text)
If Text1.Text <> "" & Text2.Text <> "" Then
Select Case Index
Case 0
Text3.Text = Y / X
Case 1
Text3.Text = Y \ X
Case 2
Text3.Text = Y Mod X
End If
End Select
End Sub 展开
3个回答
展开全部
一、
Dim X As String
Dim Y As String
定义的变量不正确!
Dim X As Single
Dim Y As Single
定义为单精度变量,不能为字符变量
二、
If Val(Text1.Text )> 0 and Val(Text2.Text )> 0 Then ‘或If X > 0 and Y > 0 Then
Select Case Index
Case 0
Text3.Text = Y / X
Case 1
Text3.Text = Y \ X
Case 2
Text3.Text = Y Mod X
End Select
End If '注意:End If应该在这里!!
三、
Index
这个变量是那里来的,没有值
应该修改为:MM = Option1(Index).Index
Select Case MM
Dim X As String
Dim Y As String
定义的变量不正确!
Dim X As Single
Dim Y As Single
定义为单精度变量,不能为字符变量
二、
If Val(Text1.Text )> 0 and Val(Text2.Text )> 0 Then ‘或If X > 0 and Y > 0 Then
Select Case Index
Case 0
Text3.Text = Y / X
Case 1
Text3.Text = Y \ X
Case 2
Text3.Text = Y Mod X
End Select
End If '注意:End If应该在这里!!
三、
Index
这个变量是那里来的,没有值
应该修改为:MM = Option1(Index).Index
Select Case MM
追问
谢谢,我改了之后运行起了,但是为什么启动之后三个单项选择按钮第一个永远都是被选中的呢?如图
追答
1、可能是三个Option控件不是数组控件;2、在Form启动中没有选择Option1(0).Value = True默认值;3、在Option1属性窗口查看Value是否是True
展开全部
你这里溢出是除以0,查检Val(Text1.Text)的值,另外&不等于and
Private Sub Option1_Click(Index As Integer)
Dim X As String
Dim Y As String
X = Val(Text1.Text)
Y = Val(Text2.Text)
If IsNumeric(X) And IsNumeric(Y) And X <> 0 Then
Select Case Index
Case 0
Text3.Text = Y / X
Case 1
Text3.Text = Y \ X
Case 2
Text3.Text = Y Mod X
End Select
End If
End Sub
Private Sub Option1_Click(Index As Integer)
Dim X As String
Dim Y As String
X = Val(Text1.Text)
Y = Val(Text2.Text)
If IsNumeric(X) And IsNumeric(Y) And X <> 0 Then
Select Case Index
Case 0
Text3.Text = Y / X
Case 1
Text3.Text = Y \ X
Case 2
Text3.Text = Y Mod X
End Select
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Option1_Click(Index As Integer)
Dim X As String ‘dim x as single
Dim Y As String 'dim y as single
X = Val(Text1.Text) ' X是字符 Val将数值型字符转化成数字,这里开始就错了
Y = Val(Text2.Text)
If Text1.Text <> "" & Text2.Text <> "" Then
Select Case Index
Case 0
Text3.Text = Y / X
Case 1
Text3.Text = Y \ X
Case 2
Text3.Text = Y Mod X
End If
End Select
End Sub
把
Dim X As String ‘dim x as single
Dim Y As String 'dim y as single
X = Val(Text1.Text) ' X是字符 Val将数值型字符转化成数字,这里开始就错了
Y = Val(Text2.Text)
If Text1.Text <> "" & Text2.Text <> "" Then
Select Case Index
Case 0
Text3.Text = Y / X
Case 1
Text3.Text = Y \ X
Case 2
Text3.Text = Y Mod X
End If
End Select
End Sub
把
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询