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

How To Utilize String Buffering Within A VB Component, Part 3

By Doug Dean


  • Read Part 1
  • Read Part 2

  • In Part 2 we looked at completing the VB component. In this part, we'll examine the ASP code needed to make the whole project come together!

    The ASP Code
    We can now use our component from any ASP page. Here we set our connection string, the SQL statement, and the number of fields that our SQL statement returns from the database. All these variables could be set locally in the MethodName() method instead of being sent as method parameters.

    <%
    '~~~~~~~~~~~~~~~~~~ Set Object ~~~~~~~~~~~~~~~~~
     Set oClass = Server.CreateObject("How2Project4.ClassName")
    
     '~~~~~~~~~~~~ Set method parameters ~~~~~~~~~~~~~
     strDbConnectionString = "strDSN"
     strSQL = "Select ExampleFieldID, ExampleField1, " & _
              "ExampleField2 FROM ExampleTable"
     intFieldCount = 3
    
    '~~~~~~~~~~~~~~ Get TABLE Record ~~~~~~~~~~~~~
     strHtmlTableTR = oClass.MethodName(strDbConnectionString, _
                                        strSQL, intFieldCount)
    %>
    
    <HTML><BODY>
    
    <TABLE BORDER="1" CELLSPACING="3">
    <%= strHtmlTableTR %>
    </TABLE>
    
    </BODY></HTML>
    
    <%
      Set oClass = Nothing
    %>
    

    Once the object is instantiated and the method called, a fully formed TABLE record (TR) will be returned as a string. Placing it between opening and closing TABLE tags will display the following:

    <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>
    

    Again, for more specific information on the database used here, and an alternative way to populate an ASP table, read the How To Pass a Variant Array Populated with a RecordSet From a VB Component to an ASP File and the How To Pass a RecordSet From a VB Component to an asp File articles!

    Happy Programming!

  • By Doug Dean


    Attachments:

  • Download the source files (in ZIP format)
  • How To Pass a Variant Array Populated with a RecordSet From a VB Component to an ASP File
  • How To Pass a RecordSet From a VB Component to an asp File
  • StrCatter - An Efficient String Concatenation Component


  • Article Information
    Article Title: How To Utilize String Buffering Within A VB Component, Part 3
    Article Author: Doug Dean
    Published Date: Friday, October 06, 2000
    Article URL: http://www.4GuysFromRolla.com/webtech/100600-1.3.shtml


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