0

I am maintaining an legacy system.
I have never dealt with Classic ASP, and I have little programming knowledge.
You want to group values having a two-dimensional array and store them in different two-dimensional arrays.
I'm getting an array subscript error and I can't fix what the problem is.

Can someone help me?

== Result data ==

idx type pos name url height rank
9 A top alex /citmi 201 15
8 C left james /oftim 198 120
7 A bottom colin /stici 170 232
6 F middle rhys /citmi 183 181
5 B top bruce /oftim 20 176
    strqry = "SELECT idx "
    strqry = strqry& ",type "
    strqry = strqry& ",pos "
    strqry = strqry& ",name "
    strqry = strqry& ",url "
    strqry = strqry& ",height "
    strqry = strqry& ",rank "
    strqry = strqry& "FROM [database].[dbo].[table] "
    strqry = strqry& "WHERE is_apply = 0 "

    dbopen()
    
    Set Rs = Dbcon.Execute(strqry)

Function AddItem(arr, val)
    ReDim Preserve arr(UBound(arr) + 1, 1) '<== Subscript out of range error
    arr(UBound(arr,1)) = val '<= Type error predicted
    AddItem = arr
End Function

Dim listA_1(0,6), listA_2(0,6), listB_1(0,6), listC_1(0,6)

    Do Until Rs.Eof
        ViewNum = CInt(Rs("rank"))
        If ((0 < ViewNum) AND (ViewNum < 80)) Then
            listA_1 = AddItem(listA_1, Rs)
        ElseIf ((80 <= ViewNum) AND (ViewNum < 100)) Then
            listA_2 = AddItem(listA_2, Rs)
        ElseIf ((180 <= ViewNum) AND (ViewNum < 200)) Then
            listB_1 = AddItem(listB_1, Rs)
        ElseIf ((280 <= ViewNum) AND (ViewNum < 300)) Then
            listC_1 = AddItem(listC_1, Rs)
        End If
        Rs.MoveNext
    Loop

Th Yoon
  • 99
  • 1
  • 3
  • 9
  • You're returning an `ADODB.Recordset` so why not just use [`rs.GetRows()` to return a 2-Dimensional Array](https://stackoverflow.com/a/22305896/692942)? – user692942 Mar 02 '22 at 11:05
  • 1
    From the [official documentation for `ReDim`](https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/scripting-articles/c850dt17(v=vs.84)) - "If you use the `Preserve` keyword, **you can resize only the last array dimension**, and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array.". – user692942 Mar 02 '22 at 11:50
  • @user692942 I'm new to Classic ASP, and I don't know why I didn't use GetRows() because I was maintaining it according to the rules and framework made by my predecessor. Thanks for your reply. – Th Yoon Mar 03 '22 at 01:53
  • 1
    @user692942 I understand enough. Thanks for your detailed explanation. – Th Yoon Mar 03 '22 at 01:53

0 Answers0