Search code examples
vbscriptcomboboxhta

HTA, Removing Selected Items from a Combo Box


So i have an HTA that populates a combo box based on SCCM client installs that are available and have not yet been run. Everything works fine except for the combo box whats supposed to happen is whatever program is selected runs, and is then installed and removed from the Combo box. However no matter what program i select the first Item is removed every time, I've tried a few different variations but nothing seems to work, any help is appreciated.

Dim i
strSelectedValues = ""
' Check all the Options of the ListBox
For i = 0 To (objComboBox.Options.Length - 1)
' Check if the Current Option is Selected
    If (objComboBox.Options(i).Selected) Then
     ' Collect only the Selected Values
        strSelectedValues = strSelectedValues & objComboBox.Options(i).Value
    End If
Next

'Remove selected program to install from the Combo box list
 ComboBox1.Remove(SelectedItem)

Solution

  • According to this authority, .remove needs the number/index of the option to remove. SelectedItem seems to be undefined/empty/for practical purposes: zero in your code; then it seems reasonable that the first option vanishes. So try

    ComboBox1.Remove ComboBox1.selectedIndex
    

    (perhaps guarded by a check that there is a selected option - or should it go into the loop?)