title: VBS multidimensional array from a For Each
body: <p>Perspective: This script will run on user login and on command with a shortcut on the desktop.  The order the application start is imperative.  Throughout the script, I require the full path and the program name. </p>
  
  <p>Problem: Each program path is a value in an array. I am trying to split each program path by “\” and get the upper bound to get the program name. Then Redim Preserve the original array and add the program on the second dimension. After reading for many hours, I grasp I can only change the last dimension, but I can’t figure out how to not get out of bound errors. This <a href="https://stackoverflow.com/questions/4588469/creating-a-multidimensional-associative-array-in-vbscript">Creating a Multidimensional, Associative Array in VBScript</a> is not trying to redim preserve from a For Each split.      </p>
  
  <pre><code>Set objFso = CreateObject("Scripting.FileSystemObject")
  
  '---Create Program Variables
  strProgram1 = "%SystemRoot%\notepad.exe" 
  strProgram2 = "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE" 
  strProgram3 = "C:\Program Files\Microsoft Office\root\Office16\ONENOTE.EXE" 
  strProgram4 = "C:\Program Files (x86)\Internet Explorer\iexplore.exe" &amp; " https://www.google.com" 'IE with URL
  
  '---Add Program Path Variables to an Array
  ReDim strProgramList(3) 
  strProgramList = Array(strProgram1,strProgram2,strProgram3,strProgram4)
  
  strProgramNameList = Array()
  strProgramRestartList = Array()
  boolNeedsRestart = false
  
  '---Iterating using For each loop to get program name. 
  ReDim Preserve strProgramList(3, 1)
  For Each strProgramPath In strProgramList
          strPathComponents = Split(strProgramPath, "\")
          strProgramName = strPathComponents(Ubound(strPathComponents))
          strProgramList(0, LBound(strProgramList) + 1) = strProgramName
  
  Next
  
  MsgBox strProgramList(0,0) &amp; vbNewLine &amp; strProgramList(1,0) &amp; vbNewLine &amp; strProgramList(2,0)  &amp; vbNewLine &amp; strProgramList(3,0) &amp; vbNewLine &amp; strProgramList(0,1) &amp; vbNewLine &amp; strProgramList(1,1) &amp; vbNewLine &amp; strProgramList(2,1) &amp; vbNewLine &amp; strProgramList(3,1)
  </code></pre>