EML
03-23-2012, 06:34 PM
Subscript out of range (Error 9)
I'm desperate. Can anyone please tell me what is wrong?
Sub LPT()
Dim n As Integer
n = 3
Dim order() As Integer
ReDim order(n, n)
order(0, 0) = 3
order(0, 1) = 1
order(0, 2) = 2
order(1, 0) = 1
order(1, 1) = 2
order(1, 2) = 3
order(2, 0) = 1
order(2, 1) = 2
order(2, 2) = 3
Dim times() As Integer
ReDim times(n, n)
times(0, 0) = 88
times(0, 1) = 10
times(0, 2) = 57
times(1, 0) = 48
times(1, 1) = 9
times(1, 2) = 5
times(2, 0) = 53
times(2, 1) = 36
times(2, 2) = 87
Dim schedule() As Integer
ReDim schedule(n, n)
schedule(0, 0) = 0
schedule(0, 1) = 0
schedule(0, 2) = 0
schedule(1, 0) = 0
schedule(1, 1) = 0
schedule(1, 2) = 0
schedule(2, 0) = 0
schedule(2, 1) = 0
schedule(2, 2) = 0
Dim matrix As Integer
matrix = n * n
For i = 0 To matrix - 1
Dim noPredecessor() As Integer
ReDim noPredecessor(n)
For j = 0 To n - 1
noPredecessor(j) = -1
Next j
For j = 0 To n - 1
For k = 0 To n - 1
If noPredecessor(j) = -1 And order(j, k) < n * n Then
noPredecessor(j) = k
End If
If noPredecessor(j) <> -1 And order(j, k) < order(j, noPredecessor(j)) Then
noPredecessor(j) = k
End If
Next k
Next j
It continues with more lines. But I noticed that If I put "next i" right after "next j", it doesn't work as I want, but I dont get an error.
I'm desperate. Can anyone please tell me what is wrong?
Sub LPT()
Dim n As Integer
n = 3
Dim order() As Integer
ReDim order(n, n)
order(0, 0) = 3
order(0, 1) = 1
order(0, 2) = 2
order(1, 0) = 1
order(1, 1) = 2
order(1, 2) = 3
order(2, 0) = 1
order(2, 1) = 2
order(2, 2) = 3
Dim times() As Integer
ReDim times(n, n)
times(0, 0) = 88
times(0, 1) = 10
times(0, 2) = 57
times(1, 0) = 48
times(1, 1) = 9
times(1, 2) = 5
times(2, 0) = 53
times(2, 1) = 36
times(2, 2) = 87
Dim schedule() As Integer
ReDim schedule(n, n)
schedule(0, 0) = 0
schedule(0, 1) = 0
schedule(0, 2) = 0
schedule(1, 0) = 0
schedule(1, 1) = 0
schedule(1, 2) = 0
schedule(2, 0) = 0
schedule(2, 1) = 0
schedule(2, 2) = 0
Dim matrix As Integer
matrix = n * n
For i = 0 To matrix - 1
Dim noPredecessor() As Integer
ReDim noPredecessor(n)
For j = 0 To n - 1
noPredecessor(j) = -1
Next j
For j = 0 To n - 1
For k = 0 To n - 1
If noPredecessor(j) = -1 And order(j, k) < n * n Then
noPredecessor(j) = k
End If
If noPredecessor(j) <> -1 And order(j, k) < order(j, noPredecessor(j)) Then
noPredecessor(j) = k
End If
Next k
Next j
It continues with more lines. But I noticed that If I put "next i" right after "next j", it doesn't work as I want, but I dont get an error.