Dynamic Listbox for HTA using VBscript

Experts,

I'm looking for a "professional appearance" solution for the following:

User input will calculate what usernames match the information provided by the user.  Say the first letter input by the user is the letter N.  All entries that start with the letter N will be populated into a listbox.  I have the population of the listbox working.

The second part I need the VB to do is REMOVE items from the listbox that no longer match the input from the user.  For example the first letter was N and the second letter is A.  Anything that doesn't start with "Na" would be removed from the list and so on.

Any ideas?
LVL 12
piattndAsked:
Who is Participating?
 
rejoinderCommented:
Here are two ways you might want to do this...
Method 1 uses a combo box.  The items remain in the drop down but as you type, the Intelli-Type tries to fill in the letters remaining for you.
Method 2 uses a list box and filter.  As you type in the filter, the names above become filtered.
<head>
<title>Your-App</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Your-App"
     BORDER="thick"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="MAXIMIZE"
     ID="oHTA"
>
<APPLICATION:HTA>
</head>
 
<script language="VBScript">
 
set dicUserNameList = CreateObject("Scripting.Dictionary")
 
Sub Window_OnLoad
    arrDropDownItems = array("Alpha","Bravo","Charlie","Delta","Echo","Foxtrot","Golf","Hotel","India","Juliet ","Kilo","Lima","Mike","November","Oscar","Papa","Quebec","Romeo","Sierra","Tango","Uniform","Victor","Whiskey","X-ray","Yankee","Zulu")
    txt_ComboBox.List = arrDropDownItems
    
    Set objList = document.getElementById( "lst_UserNames" )
    If objList Is Nothing Then
        MsgBox "A problem was encountered while creating the listview." & vbCRLF & "Please see your administrator."
    Else
        With objList
            .View              = 3
            .Width             = 360
            .Height            = 140
            .SortKey           = 0
            .Arrange           = 0
            .LabelEdit         = 1
            .SortOrder         = 0
            .Sorted            = 1
            .MultiSelect       = 0
            .LabelWrap         = -1
            .HideSelection     = -1
            .HideColumnHeaders = 0
            .OLEDragMode       = 0
            .OLEDropMode       = 0
            .Checkboxes        = 0
            .FlatScrollBar     = 0
            .FullRowSelect     = 1
            .GridLines         = 0
            .HotTracking       = 0
            .HoverSelection    = 0
            .PictureAlignment  = 0
            .TextBackground    = 0
            .ForeColor         = -2147483640
            .BackColor         = -2147483643
            .BorderStyle       = 1
            .Appearance        = 1
            .MousePointer      = 0
            .Enabled           = 1
            .ColumnHeaders.Clear
            .ColumnHeaders.Add , , "Users", 200
            .ListItems.Clear
        End With
    End If
    
    for each User in arrDropDownItems
        dicUserNameList.Add User, 1
        Set objListItem  = objList.ListItems.Add
        objListItem.Text = User
    next
End Sub
 
Sub txt_filterUserNames_onKeyUP
    Set objList = document.getElementById( "lst_UserNames" )
    objList.ListItems.Clear
    if txt_filterUserNames.Value <> "" then
        for each User in dicUserNameList
            if InStr(UCase(User),UCase(txt_filterUserNames.Value)) then
                Set objListItem  = objList.ListItems.Add
                objListItem.Text = User
            end if
        next
    else
        for each User in dicUserNameList
            Set objListItem  = objList.ListItems.Add
            objListItem.Text = User
        next
    end if
End Sub
 
</script>
<body>
Method 1<br>
<OBJECT ID="txt_ComboBox" CLASSID="CLSID:8BD21D30-EC42-11CE-9E0D-00AA006002F3" STYLE="WIDTH:160pt;HEIGHT:16pt;TABINDEX:0;ZINDEX:0;"><PARAM NAME="VariousPropertyBits" VALUE="746604571"><PARAM NAME="DisplayStyle" VALUE="3"><PARAM NAME="Size" VALUE="2540;635"><PARAM NAME="MatchEntry" VALUE="1"><PARAM NAME="ShowDropButtonWhen" VALUE="2"><PARAM NAME="FontCharSet" VALUE="0"><PARAM NAME="FontPitchAndFamily" VALUE="2"></OBJECT>
<p>&nbsp;</p>
Method 2<br>
<OBJECT id="lst_UserNames" name="lst_UserNames" classid="clsid:BDD1F04B-858B-11D1-B16A-00C0F0283628"></OBJECT>
<br>Filter: <input type="text" size="40" id="txt_filterUserNames" name="txt_filterUserNames">
</body>
</html>

Open in new window

0
 
piattndAuthor Commented:
Thank you for the code.  I also found a way to do it via a listbox and identifying which entry doesn't match, then removing them; however, I encounter a problem repopulating them again if the user backspaces a letter out.
0
 
piattndAuthor Commented:
Thanks, I'll give this a shot.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
rejoinderCommented:
Glad to help out.  If you like the second method, there are ways to add additional columns to the list as well as small images.
0
 
piattndAuthor Commented:
If you're still out there, I've dumped all user names from an AD query into a dictionary file.  I then want to dump those into the listbox and perform the filtering as you had shown in the second example.

I'm having a problem with the command to add the items into the list.  Can you still help?  Below is what I had toyed around with, nothing is working.
Sub BuildList
 
'Set objList = document.getElementByID( "lst_UserNames" )
'objList.ListItems.Clear
 
For Each strUser in dicUserNameList
	'Set objListItem = objListItem.Add
	'objListItem.Text = strUser
	txt_filterUserNames.AddItem strUser
Next
 
End Sub

Open in new window

0
 
rejoinderCommented:
Try changing the sub to this...
Sub BuildList
    Set objList = document.getElementByID( "lst_UserNames" )
    objList.ListItems.Clear
    for each User in dicUserNameList
        Set objListItem  = objList.ListItems.Add
        objListItem.Text = User
    next
End Sub

Open in new window

0
 
piattndAuthor Commented:
I'll post up another question with my scenario, I think it's too in depth now to continue on this question
0
 
rejoinderCommented:
OK.

When you post the new question, can you add a comment with a link to the new URL please?


Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.