| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 292 人关注过本帖
标题:下标越界问题请教,高手抽空帮忙看下
只看楼主 加入收藏
xiaokiss2008
Rank: 2
等 级:论坛游民
帖 子:37
专家分:20
注 册:2011-7-8
结帖率:28.57%
收藏
已结贴  问题点数:20 回复次数:2 
下标越界问题请教,高手抽空帮忙看下
程序代码:
Private Sub Command1_Click()
On Error GoTo Errhandler
                       '设置过滤器
  CommonDialog1.Filter = "数据文档(*.txt)|*.txt"
  CommonDialog1.Action = 1
  Text1 = CommonDialog1.FileName

 
Errhandler:
  Exit Sub
End Sub


Private Sub Command2_Click()
Dim s As String
ReDim f(m, n) As String
Dim a As String, b() As String, c() As String

Open Text1.Text For Input As #1
  m = 0
  Line Input #1, a
  b = Split(a, "    ")
  For n = 0 To UBound(b)
    f(m, n) = b(n)          这里出现下标越界
    n = n + 1
  Next n

 

 m = m + 1

 
  Line Input #1, a
  s = Replace(a, vbTab, "    ")
  c = Split(s, "    ")
  For n = 0 To UBound(c)
'    f(m, n) = b(n)      这里出现下标越界
    n = n + 1
  Next n

 
Close #1
Text2.Text = b(0)
Text3.Text = f(1, 1)
End Sub
总是提示下标越界,不懂啊 ,高手们教教
搜索更多相关主题的帖子: Text1 
2013-02-15 10:22
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:653
专家分:3402
注 册:2008-5-7
收藏
得分:20 
你的动态数组并没有动态调整下标,所以会出现下标越界。根据你提供的代码,你需要从文件中读取两行文本,数组m即代表行数,n是根据分隔符来决定的,由于多位数组列数必须统一,如果你的两行文本分隔符数一致的话,则程序可做如下修改:
程序代码:
Private Sub Command1_Click()
On Error GoTo Errhandler
                       '设置过滤器
  CommonDialog1.Filter = "数据文档(*.txt)|*.txt"
  CommonDialog1.Action = 1
  Text1 = CommonDialog1.FileName

Errhandler:
  Exit Sub
End Sub


Private Sub Command2_Click()
Dim s As String,f() as string
Dim a As String, b() As String, c() As String

Open Text1.Text For Input As #1
  m = 0
  Line Input #1, a
  b = Split(a, "    ")
  redim f(1,ubound(b))
  For n = 0 To UBound(b)
    f(m, n) = b(n)         
  Next n

  m = m + 1

  Line Input #1, a
  s = Replace(a, vbTab, "    ")
  c = Split(s, "    ")
  For n = 0 To UBound(c)
    if n<=ubound(b) then f(m, n) = c(n)     
  Next n

Close #1
Text2.Text = b(0)
Text3.Text = f(1, 1)
End Sub
2013-02-15 11:30
xiaokiss2008
Rank: 2
等 级:论坛游民
帖 子:37
专家分:20
注 册:2011-7-8
收藏
得分:0 
非常感谢回答我的提问   帮了大忙了 谢谢
2013-02-15 17:31
快速回复:下标越界问题请教,高手抽空帮忙看下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049915 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved