title: Sort listbox entries by name
body: <p>I've setup a VBScript hta to let my users choose a default printer. I'm currently trying to make it as clear as possible visually.</p>
  
  <p>Our printers are listed as similar to:</p>
  
  <pre><code>4th floor
  1st floor
  Block 2
  3rd floor
  etc.
  </code></pre>
  
  <p>Is anyone aware of a change I could make to the code to sort the output of these by name? Many thanks</p>
  
  <pre><code>&lt;html&gt; 
  &lt;head&gt;
      &lt;title&gt;Choose your default printer&lt;/title&gt; 
  &lt;style type="text/css"&gt; 
      body { 
          font-family:Verdana; 
          font-size: 12px; 
          color: #49403B; 
          background: #FFFFFF; 
          text-align: center; 
          } 
  &lt;/style&gt; 
  
  &lt;SCRIPT Language="VBScript"&gt;
      Sub Window_Onload
          window.resizeTo 500,550
          strComputer = "."
  
          Set objWMIService = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\cimv2")
          Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
  
          Set re = New RegExp
          re.Pattern = "^\\\\.*?\\"
  
          For Each objPrinter in colPrinters
              strPrinter = objPrinter.Name
              Set objOption = Document.createElement("OPTION")
              objOption.Text = re.Replace(strprinter, "")
              objOption.Value = strPrinter
              If objPrinter.Default Then objOption.Selected = True
              AvailablePrinters.Add(objOption)
          Next
      End Sub
  
      Sub SetDefault
          strPrinter = AvailablePrinters.Value
          Set WshNetwork = CreateObject("Wscript.Network")
          WshNetwork.SetDefaultPrinter strPrinter
          Msgbox strprinter &amp; " has been set as your default printer."
      End Sub
  &lt;/SCRIPT&gt;
  Click a printer name to set it as your default&lt;p&gt;
  &lt;select size="20" name="AvailablePrinters" onChange="SetDefault"&gt;&lt;/select&gt;
  &lt;p&gt;
  Close this window when done
  </code></pre>