Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
Syndicate this content

TX Text Control quote generator

This source code snippet requires TX Text Control ActiveX
Author:TX Text Control Support Department
Language:Visual Basic
Version:1.1
Released:March 20, 2001
Last modified:January 11, 2008
Requirements:TX Text Control ActiveX with Visual Basic
Download code:quote_generator.zip Download [277.27 KB, ZIP]

Part #1

This is a series of sample programs which show how to use TX Text Control in office applications. The main task of an office application typically is to create documents from information taken from a set of databases. For instance, a quote is generated from a record in an address database and one or more records in an article database.

The sample programs are built up in several steps, starting very simple with only a single address database in Step 1, and adding more features later on.

Step 1: When the program is started, it displays an address database in a data bound grid control. This may not be the most scalable approach, but all we need in this first version is a simple way to select a record from the database, and therefore using a grid and a data control will do for now.

Selecting the File/New Quote menu item takes the current record from the database and creates a document from it. This is done in 2 steps:

A form containing a TX Text Control is opened, and a stylesheet is loaded. A stylesheet is a file that serves as a template for the final document. It contains all text parts which are equal to all documents, for instance a phrase like "In reply to your inquiry and according to our general terms of business we are pleased to..", and placeholders for information that is to be inserted from a database, like 'Address', 'Date', and so forth. It also defines the font, font size, company logo, and layout, so that all files will have the same look.

Once the stylesheet has been loaded, the placeholders are updated from the database, so that they now contain the real address, name, customer number, and date.

The stylesheet can be edited with the Advanced menu. Later versions of the program will have additional stylesheets for other types of documents.

Design Considerations

Business applications tend to become very large over time, and often, as the company grows and changes, need to be extended in unexpected ways. Often early versions of the program use a simple desktop database, and later need to be adapted to a more powerful client/server model. Or the company suddenly has a dependancy in another country, and the software has to deal with different languages and currencies. For this reason, a modular, component based design is vital, and we will already follow this approach in the first step.

The application can be divided into several logical units:

  1. The Database module provides an interface to the physical database, and allows for later changing the database without rewriting the complete program.
  2. The DataEntry module provides the user interface to the databases, i.e. enables the user to add and edit records.
  3. The Search unit allows for searching the databases, for instance for a company name or invoice number.
  4. The Editor unit assembles and displays a document, and lets you save and print it.
  5. Visual Basic makes it straightforward to put these units into ActiveX components, providing good encapsulation and reusability.

Note that Step 1 only contains modules 1 and 4. The remaining ones, together with an additional article database, will follow in Step 2.

This is part 2 of our series about creating a quote generator with TX Text Control. (Part 1 is online). The system requirements again are Visual Basic 6 and a full or trial version of TX Text Control 7.

Before you read everything about how it is programmed, you may want to run it and see what it does, so here is a short user's guide first.

TX Text Control Quote Generator User's Guide - Creating a quote in 20 Seconds

  1. Start the program. You will see the main form, displaying some customer address records. Select one by clicking on it.
  2. Select the File / New Quote menu item. A quote will be generated using the selected customer's name, address and customer number.
  3. Click on the Insert / Article menu item. Select one of the articles displayed in the dialog box that pops up, and click OK. The product data will automatically be entered into the quote.
  4. Enter the desired quantity. The total will be recalculated accordingly.
  5. Repeat step 3 to enter more articles (clicking into an empty table row first). Delete the remaining empty lines by selecting them with the mouse and clicking Edit / Delete table rows.
  6. Finished. Click File / Print to make a printout of the quote.

Programming Details

The first thing we need to do in order to add article descriptions and pricing to our quotes from Step 1 is to add another database. We call it the article database, and display it on the main form beside the address database.

That's it for the main form. In the Editor module, we now add a menu item which lets us insert items from the article data into a quote.

A list of articles is best displayed in a table, and TX Text Control offers all required table functions to let us insert product IDs, descriptions, and prices into the respective cells, as well as to perform calculations. We therefore add a table to the style sheet and adjust its column widths, text distances, and caption text so that later only the plain text needs to be filled in.

This is what the style sheet now looks like:

A new menu item has been added to the Advanced menu, which allows to insert a table. Also, a Format/Table menu item has been created which calls TX Text Control's Table Attribute dialog box, so that we can adjust the table grid lines and background shading. The table's column widths and tabs are adjusted in the ruler bar. Note that the 2 rightmost columns have decimal tabs, so that the currency values they will contain will be properly aligned at the decimal sign.

We are now ready to fill in text from the article database into the table. The properties we need at this point are:

  • TableAtInputPos to check whether the input position is within a table
  • TableRowAtinputPos to get the current table row
  • TableColAtInputPos to get the current tablecolumn
  • TableCellText to access the text in a given table cell

After the user has selected a product in the article database, the program performs these steps:

  1. It checks if the current input position is in an empty field in the first column of a table, where a product code can be inserted. If not, then it moves the input position to the first free cell.
  2. It inserts the selected product code, product description, and price.
  3. Whenever TX Text Control sends a Change event, it checks if it was an entry in the Quantity column that has changed, and recalculates the total accordingly.

Conclusion

Some parts are still missing in order to make the quote generator ready for use in an office. For instance, there is no way to search the databases, no comfortable data entry masks, and no way to archive the generated documents.

External verification page for ISO 9000:2000 certificate
ISO 9001:2000
certified