Working With Arrays: ARRAY - Is An Indexed Variable, Meaning It Is One Variable With
Working With Arrays: ARRAY - Is An Indexed Variable, Meaning It Is One Variable With
In VB, arrays work in much the same way as they do in all other
languages you have studied.
ListBox
With the ListBox control the user can select items from a list of choices.
Although the list of choices can be entered in the List property of the control,
as in the example below, this is not a very good habit to get into. It is
essentially "hardcoding" data into the program and it can cause maintenance
headaches.
As you can
see, it is fairly
simple to load
the ListBox
and the
ComboBox
during the
From_Load
event. The
only other
detail to note
is that the
order in which
the items
appear in the
Combo is not
the same as
the order in
which the
items were
added. That is
intentional - it
is done with the Sorted property for the ComboBox. It can also be done for
the ListBox.
For this next example we need to create a new form, Form2, in the current
Project.
The control that shows the current drive is called a DriveListBox. The name
of the active drive is in the control's Drive property. The selected drive can
be changed, in code, by writing: Drive1.Drive = "D:", for example.
Don't bother looking for the .Drive property in the Properties window for Drive1 -
you won't find it. Same with Dir1.Path and List1.FileName. That's because Drive is
a runtime property. That is, one that is only available when the program runs.
Makes sense when you think about it. You can design the DriveListBox to have the
size, the color and the font you want but you can't tell it which drive will be active
at runtime. That will have to come from the system.
VB is full of these details. Every control has properties that are only accessible at
runtime, through code. The only way to find them is to look in the documentation.
A big Reference Manual is handy and the Help function helps a lot with this, too.
The default event associated with Drive1 and Dir1 is called a Change event.
That's because nothing has to be done with those controls until they are
actually changed. Remember, when the program runs they are automatically
loaded with the current drive and the current directory active.
When you click on the Start button you first have to check
if a file is selected. If not, issue a message.
The only thing to do is to Load the form using its FormName (from the Name
property) and then to execute its Show method. The argument
vbModeless means that the form does not get exclusive focus. The
opposite of vbModeless is vbModal. A modal form is one which requires
action from the user before it can be closed. Usually, error messages are
modal - you have to respond, usually by hitting the OK or Cancel button,
and you can't click on another form to send this one to the background, and
you can't close it with the close box. A modeless form can be sent to the
background and it can be closed at any time.