Home > Store

Effective Visual Basic: How to Improve Your VB/COM+ Applications

Register your product to gain access to bonus material or receive a coupon.

Effective Visual Basic: How to Improve Your VB/COM+ Applications


  • Sorry, this book is no longer in print.
Not for Sale




  • Copyright 2001
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-70476-5
  • ISBN-13: 978-0-201-70476-1

Featuring nearly fifty rules for best practice, EFFECTIVE VISUAL BASIC gives the working programmer concrete guidelines for designing better systems and writing better code. Whether the focus is COM, databases, or distributed systems using MTS and COM+, this book offers proven, timeless solutions derived from the authors’ years of experience consulting and training in the VB arena.

EFFECTIVE VISUAL BASIC addresses general practices, from defensive programming to error handling and object-oriented design. In addition, it covers the critical issues in working with COM: interfaces, compatibility, and class design. Rules for building multi-tier applications are followed by a section on best practices for programming the Web. This book also addresses databases and effective data access, among the most important uses of VB.

Highlights include:

  • Sound programming practices and object-oriented design principles, as applicable in VB.NET as in VB6
  • Writing code that runs correctly in both MTS and COM+ environments
  • Improving scalability by not necessarily configuring all your components
  • Using XML, IIS, and ASP in Web applications
  • Designing classes for efficient database access

The product of a wealth of practical experience, EFFECTIVE VISUAL BASIC enables readers to advance their skills and become more effective software developers.


Sample Content

Online Sample Chapter

Designing, Building, and Working with COM-Based Components

Downloadable Sample Chapter

Click below for Sample Chapter related to this title:

Table of Contents

1. Shifting from Liberal Arts to Software Engineering.

Maximize the Potential of VB's Compile-Time Type Checking.

Make Assumptions Explicit Via Debug.Assert.

Consider #If When Compile-Time Conditions Differ.

Raise Errors to Signal Exceptional Conditions.

Trap Locally, Act Globally: Effective Error Handling.

Know the Difference Between Type and Class.

Embrace Good Object-Oriented Design, Not Just VB.

Prefer UDTs Over Classes for Value Types.

Automate Mundane Tasks.

2. Designing, Building, and Working with COM-Based Components.

Think in Terms of Interfaces.

Use Custom Interfaces.

Define Custom Interfaces Separately, Preferably Using IDL.

Avoid the Limitations of Class-Based Events with Custom Call-Backs.

Be Deliberate about Maintaining Compatibility.

Choose the Right COM Activation Technique.

Beware of Class_Terminate.

Model in Terms of Scenarios Instead of Entities.

Avoid ActiveX EXEs Except for Simple, Small-Scale Needs.

3. MTS, COM+, and VB—The Middle Tier.

Understand the Design of MTS and COM+.

Don't Use Singletons in MTS and COM+.

Know When to Use New versus CreateObject versus GetObjectContext.CreateInstance.

Understand the Real Motivation for SetComplete.

Consider an Auto-Abort Style with Transactions.

Don't Reinvent the DBMS.

Don't Feel Obligated to Configure All Your Components.

Avoid Compiling Things into DLLs that You'll Later Regret.

Best Practices for Porting MTS Code into COM+.

Best Practices for Writing Code that Runs on MTS and COM+.

4. The Web and VB.

Understand the IIS Architecture.

Manage Application State to Maximize Efficiency.

Manage Session State to Maximize Scalability.

Understand the Differences Between DCOM and HTTP.

Write COM Components for Scripting Environments (like ASP).

Understand How Your COM Objects Interact with ASP.

Use XML Instead of Proprietary Data Formats.

Be Deliberate about Presentation vs. Business Logic.

Use XSLT to Move from Data to Presentation.

5. Effective Data Access from VB.

Efficiency Basics: Roundtrips, SQL Statements, and Providers.

Don't Over-Encapsulate Data Access.

Never Hold Database Connections as Data Members.

Deadlock is Common; Develop Defensively.

Use Firehose Cursors whenever Possible.</LI>

Make the Right Data Searching Decision (Avoid SelectSingleNode Abuse).



Visual Basic (VB) has become the most popular programming language in the United States. It is a large language and a complex product. Yet the ease with which it builds graphical user interfaces, accesses databases, and supports the Component Object Model (COM) is impressive.

This book is written by VB programmers for VB programmers. We assume you have been working with VB for quite some time and, if you’re lucky, in a variety of ways: building front ends, reading databases, generating Web pages, programming COM objects. The goal of this book is to summarize a number of effective VB techniques that we have learned—and put into practice—over the years. This book has something for everyone, from general practices and COM-based components to COM+ and distributed applications. The wider your exposure to VB and the Windows Distributed Internet Application Architecture (DNA), the more applicable you’ll find the techniques.

We follow the style of other books in the DevelopMentor series, in that each technique stands alone as an independent item ready for application. We try our best to describe each item as concisely as possible, and to let you read the book in any order you like. In a few cases, however, one rule leads quite naturally to another and thus should be read in that order; we’ll point these dependencies out to you.

If we’ve done our job, then reading this book—and taking its ideas to heart—will make you a more effective VB programmer. It will also make you a better practitioner because your skills will improve in other areas as well, such as object-oriented design, MTS, databases, and the Web.


We all work for a developer services company called DevelopMentor. It’s how we met, and how we keep abreast of the technology. It’s also a fantastic place to spend one’s working hours, and we owe this book (and much more) to our friends and coworkers at DM. If you ever want to see what DevelopMentor is all about, attend one of our Guerilla events—and be sure not to miss out on Thursday night. By the way, it’s not just the employees that make DM; it’s also the students and their energy. Thank you.

We also thank Gary Clarke for his sustained effort in getting this project off the ground and flying. We owe a great deal, as well, to Kristin Erickson (and her coworkers!) at Addison-Wesley for her tireless work behind the scenes, bringing this book to completion.

The anonymous reviewers did an excellent job, and we thank them for their hard work under a tight schedule. The book is much better as a result.

Finally, we’d like to thank our families for their boundless support and understanding during our late nights of reading, researching, writing, and reinstalling Windows.



A Abstraction, 42, 43–44, 46
Access permissions, checking, 170
ACID rules, 142, 154, 155
Activation, COM, 91, 99–110
CreateObject function, 99, 103–105
    GetObjectContext.CreateInstance and Server.CreateObject, 99, 100, 106–107
    GetObject function, 99, 105–106
    New operator, 102–103
    performance considerations, 107–110
    types of, 107–108, 109, 118–119
Active Template Library (ATL), 143
ActiveX EXEs, 118–122
Activities in MTS/COM+, 124, 126, 127–128, 131
ADO disconnected recordset, 297
ADO objects, 136–137
ADO Recordset, 231–232, 235, 273, 288
    disconnected, 297
Advanced Data Tablegram format (ADTG), 235
Apartment–threaded object, 221
    Application variable and, 223–224
    Session variable and, 222–223
API calls, 30
Application object. See ASP Application object
Application state management, 184–194
    ASP Application object, 191–193
    BAS module data and, 185–188
    SPM and, 188–191
    weighing options for, 193–194
    in conditional compilation, 15–17, 19
    in scripts, 58
ASP, 150, 175, 185
    eliminating from distributed application, 206–208
    interaction with COM, 218–227
    intrinsic objects, 219–220
        benefits of, 225–226
        disadvantages of, 226–227
    presentation layer–business logic layer separation and, 236–243
        MTS components and, 238–239
        WebClasses and, 240–243
    thread–pooling scheme, 223
    threads in, 186
ASP.dll, 175
ASP Application object, 153–154, 220
    apartment–threaded object and, 223–224
    caching using, 191–193
ASP page, object creation from, 137
ASP Session object, 194–195, 219
AspTrackThreadingModel property, 224
Assignment of class versus type, 38, 39–40
Assumptions, explicit, 8–14
ATL (Active Template Library), 143
Atomicity, issue of, 154
Auto–abort style with transactions, 146–150
Automating mundane tasks, 53–60
    with nmake, 53–56
    with Windows Scripting Host (WSH),
B Base client, 130
BAS modules, 122, 150
    caching data in, 185–188
    variables, 187–188
Batch files, 53
Batch SQL statement, 261–262
Binary Compatibility setting, 95–96, 97
Binding, client–object, 107
Binding mechanisms, client–object, 100–101
Brittle–code problem, 248–249
Browser, 237
Builds, debug versus release, 15–16
Business logic layer–presentation layer separation, 236–243
    MTS components and, 238–239
    WebClasses and, 240–243
ByRef, 36, 37, 40
ByVal, 36, 37, 40
C C++, 41
Caching, 151, 156
    of durable state web application, 184–194
        ASP Application object, 191–193
        BAS module data and, 185–188
        SPM and, 188–191
        weighing options for, 193–194
    in–memory, 150–151
Callbacks, custom, 83–90
    accessing, 66
    custom interfaces and evolution of, 67–69
    groups of, 48
    real–world entities modeled by, 42–43
    type versus, 35–41
    value types and, 49–52
Class–based events, 83–86
Class–based references, 67
Class_Initialize, 43
Class_Terminate, 43, 111–114
Cleanup, 111–114
    accidental DLL installation on, 170–171
    base, 130
    compiled, 93–96
    object binding by, 100–101
    scripting, 92–93
    storing session information on, 196–201
        via cookies, 197–198
        in database, 201–202
        in header, 197–198
        in hidden form fields, 200–201
        with QueryString variables, 199–200
Close methods, 111–112
CLSIDs, 91
Coclass (COM class) definitions, 81
CoCreateInstance, 164
CoCreateInstanceEx, 164
COM+, 119, 123–172
    activities in, 124, 126, 127–128
    Auto–Abort style with transactions, 146–150
    coding practices for, 169–172
    components configuration issues, 157–158
    context in, 157
    DBMS issues, 150–156
    design of, 124–127
    DLL issues, 159–164
    object creation in, 129–140
    porting MTS to, 164–169
        declarative security checks and, 167
        GetObjectContext.CreateInstance and, 164–165
        MSI and, 168–169
        ObjectConstruct string and,
        RefreshComponents command and, 167–168
        SafeRef and, 165
        secondary object errors and, 165–166
    SetComplete, 140–146
    singletons in, 127–129, 132
    synchronization in, 125–126
    threads in, 186
    transactional methods in, 141–142
    transaction infrastructure in, 282–283
    Windows 2000 and, 138–139, 149–150
COM. See also DCOM
    activation, 91, 99–110
        CreateObject function, 99, 103–105
        GetObjectContext.CreateInstance and Server.CreateObject, 99, 100, 106–107
        GetObject function, 99, 105–106
        New operator, 102–103


Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020