Option Explicit Private indexes(26) As Integer Private DELIM As String Private myPath As String Const NUMSTART = 48 Const CHARSTART = 65 Private letterstart As Variant Private itemType As String Private theForm As Form Dim index As Integer Dim itemValue As String ' Cancel selected. Private Sub cmdCancel_Click() Me.Hide index = -1 End Sub ' Done selected Private Sub cmdDone_Click() Me.Hide ' Attempts to call a subroutine in the calling form ' (as specified in execute call). If there is an error, ' we assume there is no handler. Handler is passed: ' - Name of item list (file passed in) ' - index of item selected ' - Array of data for the item selected. On Error Resume Next Call theForm.ListInput_Handle(CStr(itemType), CStr(index), getSelectedItemData()) On Error GoTo 0 End Sub Private Sub cmdSrch1_Click() Call jumpToCharacter("0") End Sub Private Sub cmdSrch2_Click() Call jumpToCharacter("C") End Sub Private Sub cmdSrch3_Click() Call jumpToCharacter("F") End Sub Private Sub cmdSrch4_Click() Call jumpToCharacter("I") End Sub Private Sub cmdSrch5_Click() Call jumpToCharacter("L") End Sub Private Sub cmdSrch6_Click() Call jumpToCharacter("O") End Sub Private Sub cmdSrch7_Click() Call jumpToCharacter("R") End Sub Private Sub cmdSrch8_Click() Call jumpToCharacter("U") End Sub Private Sub cmdSrch9_Click() Call jumpToCharacter("X") End Sub ' Display the dialog and accept user input Public Sub executeDialog(ByRef callbackform As Form, ByVal item As String, ByVal caption As String) Set theForm = callbackform ' If list was already loaded, no need to load it again. If (CStr(item) <> CStr(itemType)) Then itemType = item ' Only load files that exist If (checkFileExists(filename(item)) = False) Then MsgBox "File " & filename(item) & " does not exist. Unable to load list.", vbCritical, "Load List Error" Exit Sub End If ' Fill in list box loadListBox (filename(item)) End If lblCaption.caption = caption index = -1 Me.Show End Sub ' Does work of loading listbox from file and populating the ' indexes. Each item is expect on it's own line, with ' additional information separated by DELIM. ' NOTE: assumes list is already sorted in file! ' ' Example: (Time Zone:GMT offset:Description) ' USA (Easter):-500:USA Eastern Timezone Public Sub loadListBox(ByVal fname As String) Dim initChar As String Dim storeIndex As Integer lstSelections.Clear Dim a ' Yes overkill, but... On Error Resume Next File1.Open fname, fsModeInput If (Err.Number > 0) Then MsgBox "Unable to find file:" & fname & vbCrLf & _ "Application installation may be corrupt." File1.Close Exit Sub End If Dim mystr As String ' Loop through items. Do While (Not File1.EOF) mystr = File1.LineInputString ' Get each item on the line a = Split(mystr, DELIM) ' First item is the key shown to user in list lstSelections.AddItem a(0) ' Find starting character and which index it belongs to initChar = UCase(Mid(a(0), 1, 1)) storeIndex = Asc(initChar) - CHARSTART + 1 ' If less than zero, it's a special character or number If (storeIndex < 1) Then storeIndex = 0 End If ' Place in the index which index in the list. If (indexes(storeIndex) = 0) Then indexes(storeIndex) = lstSelections.NewIndex End If Loop File1.Close On Error GoTo 0 End Sub ' When user selects one of the "xyz" buttons, this handles ' moving listbox to proper line. Private Sub jumpToCharacter(ByVal mychar As String) Dim cindex As Integer Dim oldIndex As Integer ' assume uppercase! Not too hard to make it work for everything. cindex = Asc(mychar) - CHARSTART + 1 oldIndex = cindex If (cindex < 1) Then cindex = 0 Else ' Complex loop just to get to first line that had character after selected one. Do While (indexes(cindex) = 0) cindex = cindex + 1 If (cindex > 26) Then cindex = oldIndex Do While (indexes(cindex) = 0) cindex = cindex - 1 If (cindex < 1) Then Exit Sub End If Loop End If Loop End If lstSelections.TopIndex = indexes(cindex) End Sub Private Sub lstSelections_Click() index = lstSelections.ListIndex itemValue = lstSelections.List(lstSelections.ListIndex) End Sub Function checkFileExists(ByVal name As String) As Boolean Dim a a = FileSystem1.Dir(name) If (a = "") Then checkFileExists = False Else checkFileExists = True End If End Function