To read the article online, visit

How To Pass a Variant Array Populated with a RecordSet From a VB Component to an ASP Page, Part 3

By Doug Dean

  • Read Part 1
    Part 2

  • In Part 2 we examined the ASP code needed to retrieve the Recordset information from the variant array. Now, let's look at an example that uses the variant array! For my example I will construct an HTML TABLE from the array data.

    Number of records returned is
    <%=UBound(vRecordArray, 2) + 1%><BR>
    <%For lngIndex = 0 to UBound(vRecordArray, 2) %>
      <TD><%=vRecordArray(EXAMPLE_FIELD_ID, lngIndex)%></TD>
      <TD><%=vRecordArray(EXAMPLE_FIELD_1, lngIndex)%></TD>
      <TD><%=vRecordArray(EXAMPLE_FIELD_2, lngIndex)%></TD>

    Notice that the actual number of records returned is acquired by using the Ubound Method - incremented by one since the array is zero based.

    Number of records retuned:
    UBound(vRecordArray, 2) + 1

    Also take note that the For ... Next code uses indexes from 0 to UBound(vRecordArray, 2) ['zero' to 'one less' than the number of records returned]. The UBound(vRecordArray, 2) method returns the highest index of the vRecordArray array, which is 5 (0 to 5) when there are 6 records stored in the array. To loop through all 6 records, we need to loop from 0 to 5.

    Each TABLE cell is filled by looping through the array while indexing the second subscript (lngIndex) and using our constants for the first subscript.

    Resulting HTML Code
    Here's the resulting HTML code generated by or asp code, which is returned to the clients browser:

    Number of records returned is 6<BR>
    	<TD>Text Field 2a</TD>
    	<TD>Text Field 2b</TD>
    	<TD>Text Field 2c</TD>
    	<TD>Text Field 2d</TD>
    	<TD>Text Field 2e</TD>
    	<TD>Text Field 2f</TD>

    Alternative ASP Code
    Using a double loop in the asp file code will accomplish the same HTML results:

    Response.Write("<TABLE BORDER=""1"" CELLSPACING=""3"">")
    For RECORD_INDEX = 0 to UBound(vRecordArray, 2) 
      For FIELD_INDEX  = 0 to 2 
        Response.Write(vRecordArray(FIELD_INDEX, RECORD_INDEX)) 

    Happy Programming!

  • By Doug Dean


  • Download the VB Project, Database, and ASP Pages (in ZIP format)
  • Learn more about GetRows

  • Article Information
    Article Title: How To Pass a Variant Array Populated with a RecordSet From a VB Component to an ASP Page, Part 3
    Article Author: Doug Dean
    Published Date: Wednesday, August 23, 2000
    Article URL:

    Copyright 2018 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers