Page 1
Page 2
Next we will look at a few of the important
routines needed to create our list box. Listing 2
is a partial listing of the source from the frmListInput
form. Download the source for this application to get the
full source and the sample file.

Listing 2 - List Select Source
There are several procedures that are
not shown that let the user setup the directory to find
their lists and to define the delimiter used to separate
content in the lists. I want to focus on the a few important
routines that make this control work.
First, when a calling application wants
to display the form, it calls the ExecuteDialog procedure.
This routine expects a reference to a form that will handle
the user's selection, the name of the list (note: the full
path and file name are built from the simple list name),
and the caption to display in the form. This function first
checks to see if the list is the same as a previous one.
If this is so, there's no need to reload the listing file.
I did this for some minor efficiency for programs where
the same list will be used often. If it is a new list, the
routine then calls the LoadListBox procedure. Once
complete the form is displayed.
The LoadListBox handles reading
the content for the list and preparing the List control
with the appropriate phrases. For each line in the file,
the first field is used for the value in the list control.
At this time the routine also populates our index. Remember,
the control will include a set of command buttons that allow
the user to jump alphabetically to different locations in
the list. An array of 26 values is used to identify where
each character starts in the list. Another routine, discussed
later, handles gaps in the index where there were no words
starting with a particular character. The current version
of this module expects that the list be in alphabetical
order in the file. Although, we could easily read in the
file, sort, and then build the list, I decided this was
CPU cycles I rather not spend. Microsoft eVB can run pretty
slowly already, so some pre-sorting isn't out of line (and
how hard is it to use the sort function in Excel anyway!).
Each command button-such as "def"-is
used to scroll the List control to those characters in the
list. Each of the cmdSrch1_Click() procedures calls
the JumpToCharacter procedure to handle the scrolling
process. This routine looks up the location associate with
the character in the index array. If this character wasn't
present in the list (e.g. in our example above there is
a Chandler and Elizabeth, but no student whose name starts
with 'D'), a loop walks up the index looking for the first
element that does have an index. If we reach the end of
the list, we turn around and step down looking for a defined
index. In practice these loops should not iterate more than
a couple of times.
The final routine to look at is the
cmdDone_Click(). When the user makes a selection,
the control attempts to call a handler in the calling form
with the signature:
Public Sub ListInput_Handle(ByVal item
As String, ByVal itemIndex As String, ByRef itemValue As
Variant).
If it encounters an error, then the
routine makes the assumption that the handler does not exist.
The "item" value returns the list name the caller
passed in. The "itemIndex" sends the index number
of the item in the list. Finally, an array "itemValue"
is returned ordered identical to how the values are read
from the file (i.e. key first, then each item in order between
the ":").
You can see how all this ties together
by looking at a sample application that uses the control
and handles selections. Using the new control is pretty
easy. Figure 3 shows an example application. When
either the "V" button or the "
"
label is tapped, then the popup list is shown. After selecting
an item, the key value is placed in the text box and each
element from the file (in the ':' separated list) is added
to a ListBox on the form.

Figure 3
The code behind our sample form is shown
in Listing 3. You can see, it takes only one call
to execute our dialog. We hand it our form's name, the name
of the list, and the title we want displayed. Our callback
routine (ListInput_Handle) uses a Case statement
to identify which list type we should handle. This allows
us to have many different lists used by the same form.

Listing 3
Just for fun I added a screen shot of
my, still far from done, application. You can see in Figure
4 there are many labels where I use the "
"
nomenclature. I think this design is much cleaner and easier
to use than a series of combo boxes with numerous items.
Well that's all for now. Hopefully this will help you save
your users some scrolling!

Figure 4
Previous Page