It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Run-time error '9': Subscript out of range

Moderator: dafunkymunky

Run-time error '9': Subscript out of range

Postby kebbby on Sun Mar 06, 2011 8:02 am

I have this Algorithm that sorts array of integers implemented in a simple inventory system in Visual Basic 6.0 for my thesis. The system can sort items by total price, unit price, quantity, etc. But when the input number is within 7 or more digits (ex: 3,382,328), the application produces this error:

Run-time error '9':
Subscript out of range

I believe the problem occurs because the algorithm creates an array with the size equal to the largest input number (which is 3,382,328) that is why it produces an out of range error.
Is there anything that I can do with the algorithm or the programming language or the data type used? I used double as my data type. How do I solve it? Here's the code where the error occurs:

Code: Select all
Dim q, e, g As Integer
'parr(mini) = maxi
If mini <> maxi Then
If nop > 0 Then
For e = 0 To maxi + 1
'On Error GoTo hell
parri(e) = 0
'hell:
Next e
End If
If non > 0 Then
For g = 0 To Abs(mini) + 1
narr(g) = 0
Next g
End If
'distribution of data to respective array
For q = 1 To size
If Val(ListView2.ListItems(q).ListSubItems(… >= 0 Then
parri(ListView2.ListItems(q).ListSubItem… = Val(parri(ListView2.ListItems(q).ListSub… + 1
Else
narr(Abs(ListView2.ListItems(q).ListSubI… = Val(narr(Abs(ListView2.ListItems(q).List… + 1
End If
Next q
End If


the error occurs in parri(e) = 0
where it creates an array called parri with the size of e where the current value of e is in millions.

How do I fix this? Thanks.
kebbby
 
Posts: 1
Joined: Sun Mar 06, 2011 7:32 am

Who is online

Users browsing this forum: No registered users and 2 guests