请问VB高手们我的出了什么问题

wfl2007 2008-04-03 02:38:00
我的程序为:
str() = Split(Text1.Text, ",") '为数组赋值
n = UBound(str)
For i = 0 To n
Num(i) = CInt(str(i)) ——————这里出现下面越界错误,不知道是为什么?
Next i
...全文
149 点赞 收藏 17
写回复
17 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
UltraBejing 2008-04-30
不明LZ在说什么
回复
接分先!
回复
东方之珠 2008-04-04
何必要建立Num数组,浪费资源!需要运算的时候,用类型转换:cint(str(i))
回复
zdingyun 2008-04-03
以下代码运行未见错误:
Option Explicit
Dim i As Integer
Dim str() As String
Dim n As Integer
Dim num()
Private Sub Command1_Click()
str() = Split(Text1.Text, ",") '为数组赋值
n = UBound(str)
ReDim num(n)
For i = 0 To n
num(i) = CInt(str(i)) '
Print num(i)
Next
End Sub

Private Sub Form_Load()
Text1 = "1.25,36,72,43,54"
End Sub
回复
zzyong00 2008-04-03
貌似应该是n吧
回复
应该用n-1
回复
forbearORfolie 2008-04-03
别用内置函数名作为数组或变量名
text1为空,可能导致上述错误的发生
回复
clear_zero 2008-04-03
Dim Num() As Integer
Dim str() As String


dim num() as integer

str() = Split(Text1.Text, ",") '为数组赋值
n = UBound(str)
redim num(n)
For i = 0 To n
Num(i) = CInt(str(i))
Next i


'-------------
欢迎来我的小店坐坐: 程序员雅琪的小店
回复
cbm6666 2008-04-03
更正 8F

你这行肯定是错的,因为Cint是将小数转为整数的涵数,而你的str(i)既非小数也不是数值,而是文字型,当然会错.
回复
cbm6666 2008-04-03
建议楼上几位同志, 以后别再使用 str 当变量名称

Attn:楼主
Num(i) = CInt(str(i)) ——————这里出现下面越界错误,不知道是为什么?
你这行肯定是错的,因为Cint是将小蛇转为整数的涵数,而你的str(i)即非小数也不是数值,而是文字型,当然会错.


'添加 Command1 Text1

Dim num%(), i%, s
Private Sub Form_Load()
Text1.Text = "1,2,3,4,5,6,7"
End Sub

Private Sub Command1_Click()
s = Split(Text1.Text, ",") '为数组赋值
ReDim Preserve num%(UBound(s))
Me.Cls
For i = 0 To UBound(s)
num(i) = Val(s(i))
Print num(i);
Next i
End Sub

回复
vbman2003 2008-04-03
[Quote=引用 6 楼 wfl2007 的回复:]
Dim Num() As Integer
Dim str() As String
[/Quote]

dim num() as integer

str() = Split(Text1.Text, ",") '为数组赋值
n = UBound(str)
redim num(n)
For i = 0 To n
Num(i) = CInt(str(i))
Next i

我前面的没看清,如果是下标越界问题,这样就行
回复
wfl2007 2008-04-03
Dim Num() As Integer
Dim str() As String
回复
wfl2007 2008-04-03
num定义整型数组
回复
舉杯邀明月 2008-04-03
[Quote=引用 3 楼 vbman2003 的回复:]
dim num() as string

str() = Split(Text1.Text, ",") '为数组赋值
n = UBound(str)
redim num(n)
For i = 0 To n
Num(i) = CInt(str(i))
Next i
[/Quote]

顶一下.........
回复
vbman2003 2008-04-03
dim num() as string

str() = Split(Text1.Text, ",") '为数组赋值
n = UBound(str)
redim num(n)
For i = 0 To n
Num(i) = CInt(str(i))
Next i
回复
vbman2003 2008-04-03
num是怎么定义的?
回复
xayzmb 2008-04-03
For i = 0 To n -1 '错在这里
Num(i) = CInt(str(i)) ——————这里出现下面越界错误,不知道是为什么?
Next i
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7490

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2008-04-03 02:38
社区公告
暂无公告