VB Tips

Tip 1:
Break-up your code into procedures. Procedures used in one program can act as building blocks for other programs, usually with little or no modification.

Tip 2:
If a procedure must return a value, use a Function procedure. Sub procedures do not return a value.


Validating data in a control array

For this lesson, download the sample project: ReportCard.

The Visual Basic form has a powerful tool for creating multiple similar controls in a form. It's called a control array.

There is also a very useful Procedure to check the data that is input into a form to make sure that it conforms to the rules set down for the project. That's the Validate Procedure.

Before getting to the Validate procedure, just a few words on formatting the form.

It is usually required that all the controls on a form will be of the same size, color, font and spacing.

For the alignment, sizing and spacing of the controls, use the Format icon on the toolbar.

Using the Validate Procedure on a simple textbox is straightforward:

Validating textboxes in a control array is not much more difficult.

Just remember that each textbox now as an index in its name. The Validate procedure will pass the index to the code and you have to use it.

     Previous                     Next