vb 下标越界问题

[复制链接]
查看11 | 回复3 | 2011-10-30 10:38:24 | 显示全部楼层 |阅读模式
PrivateSubCommand1_Click()DimaAsString,iAsInteger,jAsInteger,hAsInteger,str1AsString,strtempAsString,pAsInteger,uAsDouble,xAsDouble,yAsDouble,zAsDouble,chAsDouble,kAsInteger,ehAsIntegerj=0i=0CommonDialog1.Filter=\"文本数据库|*.txt\"CommonDialog1.ShowOpenIfCommonDialog1.FileName\"\"ThenOpenCommonDialog1.FileNameForInputAs#1EndIfDoWhileNotEOF(1)LineInput#1,ai=i1LoopClose#1OpenCommonDialog1.FileNameForInputAs#1Dimc()AsStringReDimc(i)DoWhileNotEOF(1)LineInput#1,aj=j1c(j)=aLoopDimg()AsDoubleReDimg(1Toi,1To80)Dimm()AsStringk=1j=1h=1eh=0Whilek=ic(k)=Trim(c(k))Forp=1ToLen(c(k))Ifstrtemp\"\"OrMid(c(k),p,1)\"\"Thenstrtemp=Mid(c(k),p,1)str1=str10ThenForh=0ToUBound(m())g(k,h1)=Val(m(h))NexthEndIfk=k1WendEndSub中的g(k,h1)=Val(m(h))老是下标越界
回复

使用道具 举报

千问 | 2011-10-30 10:38:24 | 显示全部楼层
对于不确定的数组,可以用UBound函数先检查一下,就可避免此类运行时错误的发生.你的代码太长了,实在是没耐心看完了,只帮你提供个解决思路吧.
回复

使用道具 举报

千问 | 2011-10-30 10:38:24 | 显示全部楼层
Forh=0ToUBound(m())-1赞同
回复

使用道具 举报

千问 | 2011-10-30 10:38:24 | 显示全部楼层
那你监视一下代码出错中断时k和h分别是多少了,不就知道为什么会出错啦?赞同
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行