Using a string buffer in a VB component-1

Source: Internet
Author: User
Tags access database
Lesson 1:overview
--------------------------------------------------------------------------------

This article serves as a quick ' how to ' example for-using string buffering to concatenate strings in a VB
Component. The example VB code would generate a HTML TABLE record, that'll be sent to a ASP file
Being populated with data from a database table. The GetRows () method is used to acquire the data
From a example Access database.

In many circumstances, sending a Variant array populated by GetRows (), (or a RecordSet) to a ASP file
From a VB component was the recommended way to build an HTML TABLE record. Choose to
Build an HTML TABLE record, or other database dependant code, within the VB component itself before sending
It to a ASP file. This May is not set, "true believers" in ' not mixing HTML and VB code. I tend
To being agnostic and I find sacrificing orthodoxy for speed are sometimes called for with server-side
Components. In no regard, this programming choice are exemplified here.

Rather than sending the HTML code from the VB component with the Response.Write method, you can optionally
Collect the HTML within a string and send it back as a complete HTML TABLE record. This avoids the need to
Instantiate the ASP object within the VB component. It also allows other VB code to use your component
without reference to ASP. You "re just generating pure HTML code which any COM object can be use. But when
Putting together a large HTML string in VB, the concatenation operant ' & ' can slow your code down
significantly.

We ' ll be creating two methods, MethodName () and Dobuffer (). The MethodName () method would acquire data from
A database and then use this data to construct an HTML TABLE record it'll send to the calling ASP file in
One lump sum. Our ASP file would initially call the MethodName () method with an SQL statement, a connection
String, and the number of fields used in our SQL statement. In order to generate the HTML string with the
Least use the "concatenation operant", the MethodName () method would send the string fragments it uses to
Build the HTML TABLE record to the Dobuffer () method.

The supporting database file, text, and code, for this article can is downloaded here. If You "re
Unfamiliar with writing a server-side VB DLL, can read some introductory articles at my site. This
Example'll include a VB server-side DLL (ActiveX dll) consisting of one class (ClassName) and two
Methods (methodname and Dobuffer). The VB project is named How2project4.

For How2 articles in sending data to ASP files with Variant array/getrows () and recordsets:
How to pass a Variant Array populated and a RecordSet from VB Component to a ASP File
How to pass a RecordSet from a VB Component to a ASP File.

Note:
The connection string value would need to contain the Data Source Name (DSN) that should the
Established with ODBC, although any valid database connection string would work here. ADO would also need to
Be referenced in the VB Project (the "Introductory VB Component article" to "Do").

Why Use String buffering?
If you concatenate strings using the ' & ' operant, and you repeat this operation multiple times, processing
Time would be significantly delayed compared to using string buffering. Here "s example code of both
Techniques:

Concatenating using the "&" Operant:


Strhold = "Testing One,"
Strhold = Strhold & "Two,"
Strhold = Strhold & "three."



Concatenating using a string buffering method:


S1, S2, S3, "testing One,"
S1, S2, S3, "two,"
S1, S2, S3, "three."



[This code fragment uses different and variable names from the ' code in ' this article]

With large amounts of concatenating, I have experienced increases in speed of the up to 1000 times greater
When using string buffering. This is primarily due to how VB manages the memory for strings with the "&"
Operant.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.