Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2004, 02:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default dynamic multidemsion array

Can somebody please help me in creating this multideminsion array, I am pulling Dates from a database, there could be anywhere from 1 to 50 dates at any given time. I am trying to store the dates in an array to save from having to go back to the database countless times. My problem is lying in the Dim strDatesArray(20,3) I do not know how many dates the database will pull everytime. If I use strDatesArray(iRecordCount-1,3), I get an "Expected integer constant" error then if I try Redim strDatesArray(iRecordCount -1,3) it I get a "This array is fixed or temporarily locked" error. If I just leave the Dim strDatesArray(20,3) hard coded it works, but it's not dynamic enough.


Set objSelect = Server.CreateObject("ADODB.Recordset")
objSelect.Open strSQL, objConn, adOpenStatic, adLockReadOnly, adCmdText

iRecordCount = objSelect.RecordCount

If iRecordCount = 0 Then
    Response.Write "<BR><BR>No dates are available.</TD></TR>"
Else
    Dim strDatesArray(20,3)

    For i = 0 to iRecordCount -1
        strDatesArray(i,0) = objSelect("E_ID")
        strDatesArray(i,1) = objSelect("E_Holiday")
        strDatesArray(i,2) = objSelect("E_Day")
        objSelect.MoveNext
        Next

    Redim strDatesArray(iRecordCount -1,3)

    objSelect.Close
    Set objSelect = Nothing

Dim intCounter
For intCounter = 0 To iRecordCount-1
    Response.Write strDatesArray(intCounter,0) & "<BR>"
    Response.Write strDatesArray(intCounter,1) & "<BR>"
    Response.Write strDatesArray(intCounter,2) & "<BR><BR><BR>"
Next

End If

Thanks in advanced
Mike
__________________
Peace
Mike
http://www.eclecticpixel.com
 
Old July 27th, 2004, 02:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi there,

Why don't you use GETROWS() method to populate the recordset values into an array, than using a FOR loop to do that. It is much more easier that using FOR loop.
Code:
Dim strDatesArray
strDatesArray= objSelect.GetRows()
And for displaying values from array you can always use LBound() and UBound() methods based on which you can run the FOR loop that displays the values.
Code:
Dim col, row
For col=0 to uBound(strDatesArray,2)
    For row=0 to uBound(strDatesArray,1)
        Response.Write strDatesArray(col,row) & "<BR>"
    Next
    Response.Write "<p>"
Next
Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic picturebox array thomaz C# 3 September 17th, 2008 01:15 PM
Dynamic declaration of an array tenkasian C# 2 September 5th, 2007 10:14 PM
Dynamic array of struct bobwrx C# 2 September 14th, 2006 06:12 AM
Dynamic array - please help OC Beginning VB 6 5 March 21st, 2004 05:11 AM
Dynamic Control array [email protected] Visual C++ 6 September 3rd, 2003 08:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.