Professional Documents
Culture Documents
VB Programs
VB Programs
VB Programs
It repeats the enclosed block of statements while a Boolean condition is True or until the
condition becomes True. It could be terminated at any time with the Exit Do statement.
Example:
When the above code is compiled and executed, it produces the following result −
DO-WHILE LOOP
It executes a block of statements as long as a condition is True. The loop has the following
syntax:
If condition is True, all statements in the bock are executed. When the End While statement is
reached, control is returned to the While statement, which evaluates condition again. If
condition is still True, the process is repeated. If condition is False, the program resumes with
the statement following End While.
DO-UNTIL LOOP
‘Do Until’ loop is also used when you do not know the number of time you need to execute
a block of code. The first block of code in Do Until loop (Do While x<5) is equivalent to the given
below block of code.
This will give you the same output as the first block of code in Do While loop. You will see the
Welcome message four times. Similar to
Do .....Loop While, we have to Do...Loop
Until as well.
If you execute the code, you will get the output like this:
LISTBOX AND ARRAYS
ListBox - This control allows the user to select from a list of possible choices.
ListBox vs ComboBox
You can use the "AddItem" method when you have a single column listbox.
If you try to add items to a listbox that has a non empty RowSource property you will get a
"permission denied" error.
You can use the "AddItem" combined with the List property when you have multiple columns.
All list entries start with a row number of 0, and a column number of 0, ie List(0,0) = "text"
If you want to add items to a multi column listbox, you need to use "AddItem" to add a new
row and then either "List" or "Column" to add the specific items past the first column.
Both column and row numbers in a listbox start at 0 by default and not 1.
The only way to obtain the selected items in a multiple selection list box is to cycle through the
whole list.
If you data is
stored in a
two-
dimensional array you can assign the array directly using the List property.
No items selected
It is possible to display a listbox with no items selected (when the listindex = -1).
Although once an item is selected it is not possible to unselect all the items.
Multiple selections
By default only a single item can be selected although this can be changed by changing the
MultiSelect property.
You can only make multiple selections with a listbox - not a combo box.