title: HTA to read a text file and populate drop down box
body: <p>A text file example will include the following data, a name and associated IP address, in this format:</p>
  
  <pre>
  name;IP
  </pre>
  
  <p>i.e.</p>
  
  <pre>
  harry;192.168.1.14
  billy;192.168.1.22
  </pre>
  
  <p>Using VBS to read the text file and split the data into 2 parts:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub LoadDropDownName
      Set obj = CreateObject("Scripting.FileSystemObject")  'Creating a File Object
      Const ForReading = 1                    'Defining Constant Value to read from a file
      Set obj1 = obj.OpenTextFile("savedhosts.txt", ForReading) 'Opening a text file and reading text from it
      Dim str, str1
      str = obj1.ReadAll                      'All text from the file is read using ReadAll
      MsgBox str                              'Contents of a file will be displayed through message box
      'Do While obj1.AtEndofStream            'Reading text line wise using Do Loop and ReadLine
      '    str1 = obj1.ReadLine
      '    MsgBox str1
      'Loop
      Do Until obj1.AtEndOfStream
          strNextLine = obj1.ReadLine
          arrServiceList = Split(strNextLine, ";")
          Set objOption = document.CreateElement("OPTION")
          objOption.title = arrServiceList(0)
          objOption.value = arrServiceList(1)
          LoadDropDownName.Add(objOption)
          MsgBox "arrServiceList(0) = " &amp; arrServiceList(0)
          MsgBox "arrServiceList(1) = " &amp; arrServiceList(1)
      Loop
      'MsgBox ""        
      obj1.Close                              'Closing a File
      Set obj = Nothing                       'Releasing File object    
  End Sub
  </code></pre>
  
  <p><code>MsgBox str</code> works as it displays all the data from the "savedhosts.txt" file as expected.</p>
  
  <p>However I cant get </p>
  
  <pre class="lang-vb prettyprint-override"><code>MsgBox "arrServiceList(0) = " &amp; arrServiceList(0)
  MsgBox "arrServiceList(1) = " &amp; arrServiceList(1)
  </code></pre>
  
  <p>to display in a box. I have moved the <code>MsgBox</code> command to below the <code>Loop</code> line.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Loop
  MsgBox "arrServiceList(0) = " &amp; arrServiceList(0)
  MsgBox "arrServiceList(1) = " &amp; arrServiceList(1)
  'MsgBox ""      
  obj1.Close                              'Closing a File
  Set obj = Nothing                       'Releasing File object  
  </code></pre>
  
  <p>I received an error:</p>
  
  <blockquote>
    <p>Type mismatch 'arrServiceList'</p>
  </blockquote>
  
  <p>The HTML part that should capture the data from the <code>Sub</code>:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;input type='text' maxlength="15" class="enterhostip" id="INPUT-IP" name='text1'/&gt;
  </code></pre>
  
  <p>INPUT IP: user can input a new IP and will auto change when 'Saved Hostname' has chosen a new value.</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;input type="text" maxlength="20" name="hostname" id="hostname" /&gt;
  </code></pre>
  
  <p>Hostname: user can input a new name for the host</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;select id="savedhostname" maxlength="20" name="savedhostname" onchange="vbscript:LoadDropDownName" class="pwhost" /&gt;
  </code></pre>
  
  <p>Saved Hostname: dropdown data showing only the name in the savedhosts.txt file. Changing the name will execute the
  <code>LoadDropDownName</code> script and change the value of "IP-Input".</p>
  
  <p>If someone can show me an example of similar code (using VBScript) to read the contents of this text file and show the names only in a html drop down box while using a html single line text input area to auto fill the associated IP address?</p>
  
  <p>I have searched for an example of this method but cannot find any that meet this simple criteria!</p>