VB Tips

Tip 1:
To refer to a form or control that has the same name as a restricted keyword, you must either qualify it or surround it with square brackets: [ ].
For example, this code does not cause an error:
     [Loop].Visible = True

Tip 2:
Visual Basic makes writing code much easier with features that can automatically fill in statements, properties, and arguments for you. As you enter code, the editor displays lists of appropriate choices, statement or function prototypes, or values. Options for enabling or disabling these and other code settings are available on the Editor tab of the Options dialog, accessed through the Options command on the Tools menu.



Links

Working with a ComboBox



For this lesson, download the sample project: ComboBox.

The ComboBox is a very useful control.

Whenever a user has to input data into a form the risk of errors is great. Any data that is keyed by the user can be incorrectly recorded, leading to erors in data files and calculations.

Anything that can be done to minimize the risk of errors will make the application stronger and more efficient.

The ComboBox and the ListBox work in similar ways. They both offer the user a list of choices from which to choose without having to key the data.

The difference between the two is that the ListBox offers a fixed list of choices without the option to change anything.

The ComboBox on the other hand gives some flexibility in that the user is allowed to add and delete items from the list offered.

In our example, you are allowed to add an item to the list if it doesn't already exist (note that it is case sensitive). You can also delete items from the list as you wish.



visual basic 6 combobox example


Obviously, adding or removing items from te list only makes sense when the ComboBox is in a form used in a processing loop.

When new list items may appear between invoices, for example, you would give the user the option of adding the new items as they come up.

Another point to note is that the combo list of items is loaded at run-time in the Form_Load event. This is useful because it gives you the option to chnge the initial list fairly easily.

visual basic 6 combobox





     Previous                     Next