求助,用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