| 网站首页 | 业界新闻 | 群组 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
雷速体育发帖软件开发QQ118000023C语言培训|一对一辅导|零基础学编程LightningChart 快速先进的.Net图表控件
共有 312 人关注过本帖
标题:提示下标越界
只看楼主 收藏
lz_xiaohai
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2017-3-2
结帖率:40%
  已结贴   问题点数:10  回复次数:5   
提示下标越界
Private Sub MSHFlexGrid1_Click()
    Dim c As Integer
    Dim r As Integer
    Dim i As Integer
    r = MSHFlexGrid1.Row
    For i = 0 To MSHFlexGrid1.Cols
        c = i + 1
        Text1(i) = MSHFlexGrid1.TextMatrix(r, c)
    Next i
End Sub
text1数组是0-6,MSHFlexGrid1表格是1-7  老提示下标越界,需要显示第2-7列数据


2017-12-27 16:11
HVB6
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:7
帖 子:272
专家分:416
注 册:2013-10-30
  得分:4 
回复 楼主 lz_xiaohai
试试:
Private Sub MSHFlexGrid1_Click()
    Dim c As Integer
    Dim r As Integer
    Dim i As Integer
    r = MSHFlexGrid1.Row
    For i = 0 To MSHFlexGrid1.Cols
       c = c + 1
        Text1(i) = MSHFlexGrid1.TextMatrix(r, c)
        i= i + 1
    Next i
End Sub
text1数组是0-6,MSHFlexGrid1表格是1-7  老提示下标越界,需要显示第2-7列数据
2017-12-27 16:18
wds1
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:21
帖 子:218
专家分:1193
注 册:2016-3-10
  得分:4 
MSHFlexGrid1.Cols包含表头数值,如果有判断时需要去除。
 另外MSHFlexGrid1.Cols是总列数,0- MSHFlexGrid1.Cols,就多列了,所以越界。
 修改为For i = 0 To MSHFlexGrid1.Cols-1
2017-12-27 16:45
lz_xiaohai
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2017-3-2
  得分:0 
谢谢各位的回复,理解错误。。。改了一下代码好了。
Private Sub MSHFlexGrid1_Click()
    Dim c As Integer
    Dim r As Integer
    Dim i As Integer
    r = MSHFlexGrid1.Row
    For i = 0 To MSHFlexGrid1.Cols - 2
        c = i + 1
        Text1(i) = MSHFlexGrid1.TextMatrix(r, c)
    Next i
End Sub
2017-12-27 17:02
ZHRXJR
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:62
帖 子:686
专家分:3706
注 册:2016-5-10
  得分:4 
    r = MSHFlexGrid1.Row
    c = 0
    For i = 1 To MSHFlexGrid1.Cols
        c = c + 1
        Text1(i - 1).Text = MSHFlexGrid1.TextMatrix(r, c)
    Next i

    r = MSHFlexGrid1.Row
    For i = 1 To MSHFlexGrid1.Cols
        Text1(i - 1).Text = MSHFlexGrid1.TextMatrix(r, i)
    Next i

QQ    2653043392
2017-12-27 17:06
lz_xiaohai
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2017-3-2
  得分:0 
谢谢各位的回复

[此贴子已经被作者于2017-12-28 10:27编辑过]

2017-12-28 10:14







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

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