0

I think my code successfully creates the multi dimensional array because I get the right amount when I count it with UBound(DataArray).

But I get null value when I try to display one of the data as Response.Write DataArray(1,0).

Any help appreciated!

 sDateArray = Split(DateArray, ",")
    sVenueArray = Split(VenueArray, ",")

    Dim DataArray()    
    For i = 0 to uBound(sDateArray)-1 
        ReDim DataArray(i, 1)
        DataArray(i, 0) = sDateArray(i)
        DataArray(i, 1) = sVenueArray(i)
    Next

    Response.Write UBound(DataArray) & "<br /><br />"
    DataArray(1,0)
    Response.Write DataArray(1,0)  
Efe
  • 944
  • 3
  • 19
  • 37

1 Answers1

1

Try Redim Preserve DataArray(i, 1) instead of ReDim DataArray(i, 1)

...or...

sDateArray = Split(DateArray, ",")
sVenueArray = Split(VenueArray, ",")

Dim DataArray(uBound(sDateArray)-1, 1)    
For i = 0 to uBound(sDateArray)-1
    DataArray(i, 0) = sDateArray(i)
    DataArray(i, 1) = sVenueArray(i)
Next

Response.Write UBound(DataArray) & "<br /><br />"
' DataArray(1,0) ' <== commented out cos I think this might be an error - ?
Response.Write DataArray(1,0) 

Ok I was bored so I wrote this.

May not be perfect - it's been a while since I used Classic ASP

Function SortByDate(a_input)

    x = UBound(a_input, 1) - 1
    if( x < 1 ) Then
        Response.Write "<p>Invalid input array - first element is empty</p>"
        Stop
    End If
    Dim a_output(x, 1)
    Dim earliest_date

    For j=0 To x
        earliest_date = -1
        For i=0 To UBound(a_input, 1) - 1
            If a_input(0, i) <> "" Then
                If earliest_date = -1 Then
                    earliest_date = i
                Else
                    If CDate(a_input(0,i)) > CDate(a_input(0,earliest_date)) Then
                        earliest_date = i
                    End If
                 End If
            End If
        Next
        a_output(0, i) = a_input(0, earliest_date)
        a_output(1, i) = a_input(1, earliest_date)
        a_input(0, earliest_date) = "" ' this one is done so skip next time '
    Next

    SortByDate = a_output
End Function
CompanyDroneFromSector7G
  • 4,291
  • 13
  • 54
  • 97
  • I actually tried that before but I get Subscript out of range error. – Efe Jun 01 '12 at 13:18
  • Is the `DataArray(1,0)` on the second-last line a typo? – CompanyDroneFromSector7G Jun 01 '12 at 13:25
  • This worked! But I have another issue now. How can I sort these by date? – Efe Jun 01 '12 at 13:32
  • Unfortunately there's no easy way to sort an array in Classic ASP so you'll need to write a function to do it! Google will help, but you can start [here](http://stackoverflow.com/questions/268648/how-do-i-sort-arrays-using-vbscript) and [this](http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=83) is also a good link – CompanyDroneFromSector7G Jun 01 '12 at 13:39
  • Hey bukko thanks a lot for continuing to look at this. But sort date function is not working properly. Dim a_output(UBound(a_input(0)) - 1, 1) -------------^ – Efe Jun 01 '12 at 15:25
  • Woops - sorry I forgot you don't use Return to return a value from a function in classic ASP, and the UBound function syntax was wrong! Can you try again? Sorry I can't test it here! – CompanyDroneFromSector7G Jun 01 '12 at 15:31
  • Sorry - that darned UBound again! Try now – CompanyDroneFromSector7G Jun 01 '12 at 19:08
  • Expected integer constant error again... Dim a_output(UBound(a_input, 1) - 1, 1) -------------^ – Efe Jun 04 '12 at 14:49