title: Splitting String into Array Errors
body: <p>Trying to write a script that will be run in WinPE, that essentially gets the IP address of the localhost and chooses an action based on the IP range.</p>
  
  <p>In Windows, the script runs flawlessly. However, in WinPE, I'm getting the following error:</p>
  
  <blockquote>
    <p>script.vbs(1,1) Microsoft VBScript runtime error: Subscript out of range</p>
  </blockquote>
  
  <p>Google-fu is telling me that has something to do with my array being outside of the range. Here I thought I had a decent understanding, but apparently not.</p>
  
  <p>Code that works as is on Windows:</p>
  
  <pre><code>Option Explicit
  
  Dim sIP, sHostname,sPingBat
  Dim aIP
  Dim iOct1, iOct2, iOct3, iOct4, iReturn
  Dim oWMIService, oCmd, oAdapter
  Dim cAdapters
  
  iReturn = 999
  sHostname = "."
  Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; sHostname &amp; "\root\cimv2")
  Set cAdapters = oWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
  Set oCmd = CreateObject("Wscript.Shell")
  
  For Each oAdapter in cAdapters
      If Not IsNull(oAdapter.IPAddress) Then 
          sIP = Trim(oAdapter.IPAddress(0))
      Else
          iReturn = 404
          WScript.Quit iReturn
      End If
  Next
  
  sIP = CStr(sIP)
  
  aIP = Split(sIP, ".")
  
  iOct1 = CInt(aIP(0))
  iOct2 = CInt(aIP(1))
  iOct3 = CInt(aIP(2))
  iOct4 = CInt(aIP(3))
  </code></pre>
  
  <p>Now, if I change the declaration of the aIP array to either of the following:</p>
  
  <pre><code>aIP()
  aIP(4)
  </code></pre>
  
  <p>and run</p>
  
  <pre><code>aIP = Split(sIP, ".")
  </code></pre>
  
  <p>I get</p>
  
  <blockquote>
    <p>script.vbs(26, 1) Microsoft VBScript runtime error: Type mismatch</p>
  </blockquote>
  
  <p>Changing the array assignment / split line to</p>
  
  <pre><code>aIP() = Split(sIP,".")
  </code></pre>
  
  <p>results in</p>
  
  <blockquote>
    <p>script.vbs(26, 1) Microsoft VBScript runtime error: Subscript out of range</p>
  </blockquote>
  
  <p>So I'm obviously doing something wrong.</p>
  
  <p>It's also entirely possible that my original error message is completely unrelated to my array range, and WinPE just doesn't like my script (in which case, if anybody has any pointers, it'd be appreciated)</p>
  
  <p>At the moment, I'm mounting my wim to get the install packages to make sure the WMI and Scripting packages are installed from the ADK.</p>