To read the article online, visit http://www.4GuysFromRolla.com/webtech/082300-1.3.shtml

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.

    <HTML><HEAD><TITLE>How2 EXAMPLE</TITLE></HEAD><BODY>
    
    Number of records returned is
    <%=UBound(vRecordArray, 2) + 1%><BR>
    
    <TABLE BORDER="1" CELLSPACING="3">
    <%For lngIndex = 0 to UBound(vRecordArray, 2) %>
      <TR>
      <TD><%=vRecordArray(EXAMPLE_FIELD_ID, lngIndex)%></TD>
      <TD><%=vRecordArray(EXAMPLE_FIELD_1, lngIndex)%></TD>
      <TD><%=vRecordArray(EXAMPLE_FIELD_2, lngIndex)%></TD>
      </TR>
    <%Next%>
    </TABLE>
    
    </BODY></HTML>
    

    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:

    <HTML><HEAD><TITLE>How2 EXAMPLE</TITLE></HEAD><BODY>
    
    Number of records returned is 6<BR>
    
    <TABLE BORDER="1" CELLSPACING="3">
    
    	<TR>
    	<TD>1</TD>
    	<TD>100</TD>
    	<TD>Text Field 2a</TD>
    	</TR>
    
    	<TR>
    	<TD>2</TD>
    	<TD>200</TD>
    	<TD>Text Field 2b</TD>
    	</TR>
    
    	<TR>
    	<TD>3</TD>
    	<TD>300</TD>
    	<TD>Text Field 2c</TD>
    	</TR>
    
    	<TR>
    	<TD>4</TD>
    	<TD>400</TD>
    	<TD>Text Field 2d</TD>
    	</TR>
    
    	<TR>
    	<TD>5</TD>
    	<TD>500</TD>
    	<TD>Text Field 2e</TD>
    	</TR>
    
    	<TR>
    	<TD>6</TD>
    	<TD>600</TD>
    	<TD>Text Field 2f</TD>
    	</TR>
    
    </TABLE>
    
    </BODY></HTML>
    

    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) 
      Response.Write("<TR>")
      For FIELD_INDEX  = 0 to 2 
        Response.Write("<TD>")
        Response.Write(vRecordArray(FIELD_INDEX, RECORD_INDEX)) 
        Response.Write("</TD>")
      Next 
      Response.Write("</TR>")
    Next 
    
    Response.Write("</TABLE")
    %>
    

    Happy Programming!

  • By Doug Dean


    Attachments:

  • 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: http://www.4GuysFromRolla.com/webtech/082300-1.3.shtml


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