VB Tips

Tip 1:
The user is in control. The user must feel he is in charge of the application. He must have a certain amount of control over such things as window size, window position, choice of fonts, etc.

Tip 2:
Always supply feedback. The user should always know that something is going on, especially if it's in the background and may take several minutes to run. Display an hourglass or a progress meter or a status bar so that the user doesn't start to hit keys at random to get something to happen.


Using a control array in a Visual Basic form

Whenever you have to design a form with several controls that do the same thing, consider using a control array.

A control array is not an array that controls, it's an array of controls.

In the Invoicing example from the previous lesson, we must have 3 textboxes for items and 3 textboxes for prices. We'll create 2 control arrays - one for items and one for prices.

Creating a control array is really simple:
vb 6 textbox

vb 6 control array

The biggest advantage of creating a control array is that you can then use the looping structures to manipulate them.

If, for example, I wish to clear 3 textboxes defined in an array, I use a For...Next construct:

     For i = 0 To 2
          txtItems(i).Text = ""
          txtPrices(i).Text = 0

Note that the index for an array starts at 0. You always increment index values from 0 to n-1, where n is the number of elements in the array.

If I decide to use 10 textboxes for items and prices, I can use the same code, but change the index:

     For i = 0 To 9
          txtItems(i).Text = ""
          txtPrices(i).Text = 0

     Previous                     Next