By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,327 Members | 2,627 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,327 IT Pros & Developers. It's quick & easy.

Runtime Error 9

P: 63
I have a VB 6.0 pgm and an important function in it I am trying to put a set of strings into an array. I have put important parts of the code below

Dim sortArray() As String
Set rsRoute = gdbFML.OpenRecordset(strSQL, dbOpenDynaset)

ctr = rsRoute.RecordCount
ReDim sortArray(0 To ctr)
i = 0

If Not rsRoute.EOF Then
Do While Not rsRoute.EOF

tempStr = LVS_item & LVS_desc & LVS_uspd & LVS_activity

sortArray(i) = tempStr
List1.AddItem tempStr, i
List1.Selected(List1.NewIndex) = True
i = i + 1

When i put the line in bold, i.e., sortArray(i) = tempStr, the code stops and says 'subscript out of range' I am not able to figure it out. Could someone plz help me out.
Sep 19 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 8,434
Intead of this...

ctr = rsRoute.RecordCount

...try putting this...

Expand|Select|Wrap|Line Numbers
  1. If rsRoute.RecordCount Then
  2.   rsRoute.MoveLast
  3.   rsRoute.MoveFirst
  4.   ctr = rsRoute.RecordCount
  5. End If
You see, in some circumstances, the records aren't actually counted until you "reach" them. The RecordCount will initially be either 0 (nothing found) or 1 (something found) but won't tell you how many. The MoveLast forces... um... the Jet Engine, or VB or whatever... to count them, thus updating the value in RecordCount.
Sep 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.