Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Dynamic Listbox for HTA using VBscript

Posted on 2009-05-01
8
Medium Priority
?
2,679 Views
Last Modified: 2012-05-06
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?
0
Comment
Question by:piattnd
  • 4
  • 4
8 Comments
 
LVL 14

Accepted Solution

by:
rejoinder earned 2000 total points
ID: 24282502
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
 
LVL 12

Author Closing Comment

by:piattnd
ID: 31576983
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
 
LVL 12

Author Comment

by:piattnd
ID: 24296860
Thanks, I'll give this a shot.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:rejoinder
ID: 24296914
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
 
LVL 12

Author Comment

by:piattnd
ID: 24311660
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
 
LVL 14

Expert Comment

by:rejoinder
ID: 24316525
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
 
LVL 12

Author Comment

by:piattnd
ID: 24317918
I'll post up another question with my scenario, I think it's too in depth now to continue on this question
0
 
LVL 14

Expert Comment

by:rejoinder
ID: 24318131
OK.

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


Thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question