VB Tips

Tip 1:
Never use the : to write multiple statements on one line, even if it is allowed. It makes programs harder to debug.

Tip 2:
Always use the & operator when linking strings and the + operator when working with numerical values. Using the + operator to concatenate may cause problems when operating on two variants.



Links

Creating the Visual Basic Form



To do this tutorial you may want to download the Project file so that you can follow along. This example will be used for several of the tutorials that follow.

It is recommended however that you create your own Project to become more familiar with all the details of form creation and maintenance.

Download the sample Visual Basic Project from here: the project is called Invoicing.

It is stored as a .zip file to minimize the download time. Don't forget to extract the files before using them.

As mentioned in the previous tutorial, you must first assign a color and font to the form and then name it and save it.

Then you will create some basic controls. Visual Basic Controls are objects that determine what the form does. Labels, Buttons, Textboxes are all controls. You get the contols from the Toolbox and drag them onto the form.





Before you build the Form you should know what it is going to be used for.

For our Invoicing Project, here is what the specifications might say:

SAMPLE PROJECT SPECIFICATIONS

You must build a form so that the user at the Order Desk can input a customer's purchases.

The user will input the customer's name and will select the customer's city from a list of 5 cities that will be shown to him.

If the customer is from 'Capital City' he must pay 8% tax on his purchases. Otherwise, there is no tax.

The user will then input from 1 to 3 items that the customer purchased along with the price of each item.

The maximum price for an item is 50. Anything over that is 'Too big'. If there is a price entered for an item there must be a description also.

If an item is being returned instead of purchased, the price will be negative and a red flag with the word 'Credit' will appear next to the price.

When the user hits the 'Calculate' button, the subtotal, the tax payable and the final total will appear.

There must be the usual buttons to clear the form and to exit when finished.

There is also a need for a Menu function to be able to cut, copy and paste text from different parts of the form.



The first thing to do is to create all the required controls.

However, because the items and the prices are a special case, don't do them yet. We'll cover them in the next lesson.

Your form should look something like this:









     Previous                     Next