To enhance performance and resources, I’ve just started to use getRows() on a few of my scripts. I have just come across an issue, which I’d like to ask about.
I was doing this to get the recordset and to get the count:
If NOT rs.EOF Then
arrResultSet = rs.GetRows()
arrRowCount = UBound(arrResultSet,2)
End If
But then I realised I was missing a record so I added 1 to my count:
If NOT rs.EOF Then
arrResultSet = rs.GetRows()
arrRowCount = UBound(arrResultSet,2) + 1
End If
But now I get an error later in my script when I try accessing the data array which is purely down to adding one to my count:
For iCounter = 0 to arrRowCount
...some code...
If LCase(Trim(peopleWord)) = LCase(Trim(arrResultSet(1,iCounter))) Then
...some code...
Next
Microsoft VBScript runtime error '800a0009'
Subscript out of range: 'lcase(...)'
Any help greatly appreciated.
Your
Foris going from the index of 0 to the index of thearrRowCount.So, for example, if you have three records, you are going from 0 to 3, which is 4, right? IIRC, we used to do this:
For iCounter = 0 to arrRowCount - 1Edit: Perhaps this example will help you. This web page details why using
GetRowsyields a performance improvement, so I think you’re on the right track. I have included the entire code sample, but you are interested in the part at the end. It has less code, and fewer variables, than you are using. It looks cleaner, simpler.