| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1086 人关注过本帖
标题:求助,用VB6.0编写车间调度的程序,总说下标越界
只看楼主 加入收藏
amonada
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-11-16
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
求助,用VB6.0编写车间调度的程序,总说下标越界
程序如下,怎么改都不对啊



Private Sub Command3_Click()

Dim m As Integer
Dim n As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim g As Integer
Dim h As Integer
Dim temp1 As Integer
Dim temp2 As Integer


Pc = Val(Text3.Text)
Pm = Val(Text6.Text)
zhongqunguimo = Val(Text3.Text)
gongjianshu = Val(MSHFlexGrid2.Rows) - 1

For m = 1 To zhongqunguimo
  gongxushu(m) = 0
  Numoripool(m) = 0
  For n = 1 To 100
    oripool(m, n) = 0
  Next n
Next m

For i = 1 To gongjianshu
   gongxushu(i) = MSHFlexGrid2.TextMatrix(i, 2)  这一行下标越限!!!!
Next i

zonggongxushu(0) = 1
  
For i = 1 To gongjianshu + 1
   zonggongxushu(i) = 0
Next i

For i = 1 To gongjianshu
   zonggongxushu(i) = zonggongxushu(i - 1) + gongxushu(i)
Next i

genelong = zonggongxushu(gongjianshu) - 1

For m = 1 To zhongqunguimo
   For k = 0 To gongjianshu - 1
      For n = zonggongxushu(k) To zonggongxushu(k + 1) - 1
         oripool(m, n) = k + 1
      Next n
   Next k
Next m

Randomize

For g = 1 To zhongqunguimo
    For k = 1 To 50
        temp1 = Int(genelong * Rnd + 1)
        temp2 = Int(genelong * Rnd + 1)
        n = 1
        If temp1 <> temp2 And oripool(g, temp1) <> oripool(g, temp2) Then
            n = oripool(g, temp1)
            oripool(g, temp1) = oripool(g, temp2)
            oripool(g, temp2) = n
        End If
    Next k
Next g


generation = 0
While generation < Val(Text2.Text)
    generation = generation + 1
    Call decode
    Call calculatefitness
    Call crossover
    Call mutation
Wend

End Sub



Private Sub decode() ''''解码

Dim i As Integer
Dim j As Integer
Dim m As Integer
Dim n As Integer
Dim k As Integer
Dim n2 As Integer
Dim m3 As Integer
Dim neworipool(100, 100) As Integer
Dim gongxukaishishijian(100, 100) As Single

jiqishu = Val(MSHFlexGrid1.Cols) - 3


For i = 1 To 100
    For j = 1 To 100
        a(i, j) = 0
        c(i, j) = 0
    Next j
Next i

For i = 2 To gongjianshu
    For j = 2 To gongxushu(i)
     If MSHFlexGrid3.TextMatrix(i, j) = "-" Then
       a(i, j) = 999
     Else
       a(i, j) = CSng(MSHFlexGrid3.TextMatrix(i, j))
    End If
   Next j
Next i

For i = 2 To gongjianshu
    For j = 2 To gongxushu(i)
     If MSHFlexGrid4.TextMatrix(i, j) = "-" Then
       c(i, j) = 999
     Else
       c(i, j) = CSng(MSHFlexGrid4.TextMatrix(i, j))
     End If
    Next j
Next i

For m = 1 To zhongqunguimo
   tmax = 0
   wangongshijian(m) = 0
   
   For i = 1 To genelong
      b(i) = 0
      g(i) = 0
      tv(m, i) = 0
      For j = 1 To genelong
         For k = 1 To gongjianshu
            ts(i, j, k) = 0
            tf(i, j, k) = 0
            tms(i, j, k) = 0
            tmf(i, j, k) = 0
         Next k
      Next j
   Next i
   
   For n = 1 To genelong
      b(oripool(m, n)) = b(oripool(m, n)) + 1
      For k = 1 To jiqishu
        For i = 1 To gongjianshu
           For j = 1 To gongxushu(i)
             If a(oripool(m, n), j) = k Then
              g(k) = g(k) + 1
             End If
           Next j
        Next i
      Next k
      
      For k = 1 To jiqishu
         
            If tmf(k, g(k) - 1, 1) < tf(oripool(m, n), k - 1, 1) Then     这一行的tmf下标越界!!!!!1
               ts(oripool(m, n), k, 1) = tf(oripool(m, n), k - 1, 1)
               tms(k, g(k), 1) = ts(oripool(m, n), k, 1)
               tf(oripool(m, n), k, 1) = ts(oripool(m, n), k, 1) + c(oripool(m, n), k)
               tmf(k, g(k), 1) = tf(oripool(m, n), k, 1)
            Else
               ts(oripool(m, n), k, 1) = tmf(k, g(k) - 1, 1)
               tms(k, g(k), 1) = ts(oripool(m, n), k, 1)
               tf(oripool(m, n), k, 1) = ts(oripool(m, n), k, 1) + c(oripool(m, n), k)
               tmf(k, g(k), 1) = tf(oripool(m, n), k, 1)
            End If
            
            
            
             If tmf(k, g(k) - 1, 2) < tf(oripool(m, n), k - 1, 2) Then
               ts(oripool(m, n), k, 2) = tf(oripool(m, n), k - 1, 2)
               tms(k, g(k), 2) = ts(oripool(m, n), k, 2)
               tf(oripool(m, n), k, 2) = ts(oripool(m, n), k, 2) + c(oripool(m, n), k)
               tmf(k, g(k), 2) = tf(oripool(m, n), k, 2)
            Else
               ts(oripool(m, n), k, 2) = tmf(k, g(k) - 1, 2)
               tms(k, g(k), 2) = ts(oripool(m, n), k, 2)
               tf(oripool(m, n), k, 2) = ts(oripool(m, n), k, 2) + c(oripool(m, n), k)
               tmf(k, g(k), 2) = tf(oripool(m, n), k, 2)
            End If
            
            
            
             If tmf(k, g(k) - 1, 3) < tf(oripool(m, n), k - 1, 3) Then
               ts(oripool(m, n), k, 3) = tf(oripool(m, n), k - 1, 3)
               tms(k, g(k), 3) = ts(oripool(m, n), k, 3)
               tf(oripool(m, n), k, 3) = ts(oripool(m, n), k, 3) + c(oripool(m, n), k)
               tmf(k, g(k), 3) = tf(oripool(m, n), k, 3)
            Else
               ts(oripool(m, n), k, 3) = tmf(k, g(k) - 1, 3)
               tms(k, g(k), 3) = ts(oripool(m, n), k, 3)
               tf(oripool(m, n), k, 3) = ts(oripool(m, n), k, 3) + c(oripool(m, n), k)
               tmf(k, g(k), 3) = tf(oripool(m, n), k, 3)
            End If
            
         
         
            If tmf(k, g(k) - 1, 4) < tf(oripool(m, n), k - 1, 4) Then
               ts(oripool(m, n), k, 4) = tf(oripool(m, n), k - 1, 4)
               tms(k, g(k), 4) = ts(oripool(m, n), k, 4)
               tf(oripool(m, n), k, 4) = ts(oripool(m, n), k, 4) + c(oripool(m, n), k)
               tmf(k, g(k), 4) = tf(oripool(m, n), k, 4)
            Else
               ts(oripool(m, n), k, 4) = tmf(k, g(k) - 1, 4)
               tms(k, g(k), 4) = ts(oripool(m, n), k, 4)
               tf(oripool(m, n), k, 4) = ts(oripool(m, n), k, 4) + c(oripool(m, n), k)
               tmf(k, g(k), 4) = tf(oripool(m, n), k, 4)
            End If
            
            
            
             If tmf(k, g(k) - 1, 5) < tf(oripool(m, n), k - 1, 5) Then
               ts(oripool(m, n), k, 5) = tf(oripool(m, n), k - 1, 5)
               tms(k, g(k), 5) = ts(oripool(m, n), k, 5)
               tf(oripool(m, n), k, 5) = ts(oripool(m, n), k, 5) + c(oripool(m, n), k)
               tmf(k, g(k), 5) = tf(oripool(m, n), k, 5)
            Else
               ts(oripool(m, n), k, 5) = tmf(k, g(k) - 1, 5)
               tms(k, g(k), 5) = ts(oripool(m, n), k, 5)
               tf(oripool(m, n), k, 5) = ts(oripool(m, n), k, 5) + c(oripool(m, n), k)
               tmf(k, g(k), 5) = tf(oripool(m, n), k, 5)
            End If
            
            
            
             If tmf(k, g(k) - 1, 6) < tf(oripool(m, n), k - 1, 6) Then
               ts(oripool(m, n), k, 6) = tf(oripool(m, n), k - 1, 6)
               tms(k, g(k), 6) = ts(oripool(m, n), k, 6)
               tf(oripool(m, n), k, 6) = ts(oripool(m, n), k, 6) + c(oripool(m, n), k)
               tmf(k, g(k), 6) = tf(oripool(m, n), k, 6)
            Else
               ts(oripool(m, n), k, 6) = tmf(k, g(k) - 1, 6)
               tms(k, g(k), 6) = ts(oripool(m, n), k, 6)
               tf(oripool(m, n), k, 6) = ts(oripool(m, n), k, 6) + c(oripool(m, n), k)
               tmf(k, g(k), 6) = tf(oripool(m, n), k, 6)
            End If
         
            If tv(m, 1) < tmf(k, g(k), 1) Then
               tv(m, 1) = tmf(k, g(k), 1)
            End If
            
            
            If tv(m, 2) < tmf(k, g(k), 2) Then
               tv(m, 2) = tmf(k, g(k), 2)
            End If
            
            
            If tv(m, 3) < tmf(k, g(k), 3) Then
               tv(m, 3) = tmf(k, g(k), 3)
            End If
            
            
            If tv(m, 4) < tmf(k, g(k), 4) Then
               tv(m, 4) = tmf(k, g(k), 4)
            End If
            
            
            If tv(m, 5) < tmf(k, g(k), 5) Then
               tv(m, 5) = tmf(k, g(k), 5)
            End If
            
            
            If tv(m, 6) < tmf(k, g(k), 6) Then
               tv(m, 6) = tmf(k, g(k), 6)
            End If
         
      Next k
   Next n
   
  
      wangongshijian(m) = tv(m, 1) + tv(m, 2) + tv(m, 3) + tv(m, 4) + tv(m, 5) + tv(m, 6)
  
Next m

tmax = wangongshijian(1)
For m = 1 To zhongqunguimo
   If tmax < wangongshijian(m) Then
      tmax = wangongshijian(m)
   End If
Next m
         
For i = 1 To zhongqunguimo
   Numoripool(i) = 0
      For j = 1 To zhongqunguimo
        If wangongshijian(i) = wangongshijian(j) Then
            Numoripool(i) = Numoripool(i) + 1
        End If
      Next j
Next i

End Sub
搜索更多相关主题的帖子: Dim For Next If End 
2017-11-16 20:04
wds1
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:49
帖 子:393
专家分:2025
注 册:2016-3-10
收藏
得分:10 
你的程序贴的不全,数组多没有定义,运行报错。

gongxushu(i) = MSHFlexGrid2.TextMatrix(i, 2)  这一行下标越限!!!!

如果是gongxushu(i)的越界,在赋值前用redim gongxushu(i) 定义
如果是MSHFlexGrid2.TextMatrix(i, 2)的越界,是MSHFlexGrid2已分配的列或者行不够,用MSHFlexGrid2.cows=i+1或者MSHFlexGrid2.rols=i+1在赋值前

If tmf(k, g(k) - 1, 1) < tf(oripool(m, n), k - 1, 1) Then     这一行的tmf下标越界!!!!!

这个的排错方法与上面的类似,看是那个数组。

2017-11-16 20:52
xiangyue0510
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:86
帖 子:941
专家分:5244
注 册:2015-8-10
收藏
得分:10 
正如楼上所说,你的代码不全无法准确判断。
下标越界
1. 超过上下限。定义数组a(1 to 10),你用了a(i),i>10或者i=0都不行。 多维数组也一样
2. 维度不对好像也是这个错误,比如定义数组b(1,2), 但是你用了b(1,2,3)
3. list、grid这种空间与数组类似。
建议在报错的地方加中断,查看数组、grid的使用是否正常
2017-11-17 08:52
快速回复:求助,用VB6.0编写车间调度的程序,总说下标越界
数据加载中...
 
   



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

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