Author Topic: Run-time error 9: Subscript out of range  (Read 3950 times)

Offline Testlund

  • Bot God
  • *****
  • Posts: 1574
    • View Profile
Run-time error 9: Subscript out of range
« on: October 28, 2005, 03:56:45 PM »
Despite the solution mensioned here the bug still remains. (Give us 24 hours to try out a solution before putting it into solved bugs section)

ROUTINE:

Public Function NextElement(ByRef DNA() As block, beginning As Integer, tipo As Integer, value As Integer) As Integer
  'takes the input for the first value in a gene and returns the position of the next statement
  'as defined by tipo and value
  Dim k As Integer
  Dim uboundarray As Long
 
  uboundarray = UBound(DNA())
  If DNA(uboundarray).tipo <> 4 And DNA(uboundarray).value <> 4 Then
    ReDim Preserve DNA(uboundarray + 1)
    DNA(uboundarray + 1).tipo = 4
    DNA(uboundarray + 1).value = 4
  End If
  k = beginning
 
  If beginning > 0 And beginning < uboundarray Then
    While Not (DNA(k).tipo = 4 And DNA(k).value = 4) And Not (DNA(k).tipo = tipo And DNA(k).value = value)
      k = k + 1
    Wend
    If Not (DNA(k).tipo = tipo And DNA(k).value = value) Then k = -1
  Else 'beginning wasn't valid
    k = -1
  End If

OFFENDING CODE:

While Not (DNA(k).tipo = 4 And DNA(k).value = 4) And Not (DNA(k).tipo = tipo And DNA(k).value = value)

HOVERING INFO:

DNA(k).tipo = <Subscript out of range>

k = 102

Value = 1
The internet is corrupt and controlled by criminally minded people.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Run-time error 9: Subscript out of range
« Reply #1 on: October 28, 2005, 04:00:46 PM »
change:

 If beginning > 0 And beginning < uboundarray Then
While Not (DNA(k).tipo = 4 And DNA(k).value = 4) And Not (DNA(k).tipo = tipo And DNA(k).value = value)
k = k + 1
Wend
If Not (DNA(k).tipo = tipo And DNA(k).value = value) Then k = -1
Else 'beginning wasn't valid
k = -1
End If

to

 If beginning > 0 And beginning < uboundarray Then
While Not (DNA(k).tipo = 4 And DNA(k).value = 4) And Not (DNA(k).tipo = tipo And DNA(k).value = value)
k = k + 1
if k > uboundarray then
k = k - 1
goto endbug
end if
Wend
endbug:
If Not (DNA(k).tipo = tipo And DNA(k).value = value) Then k = -1
Else 'beginning wasn't valid
k = -1
End If

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Run-time error 9: Subscript out of range
« Reply #2 on: November 15, 2005, 11:37:07 AM »
This is OLD code from v2.37.4.

It is FIXED already in v2.37.5.

This bug already been well and truly squished.
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D