Listing 1: Multi_D_ArrayFunc.vbs ' Use a comma-separated value (CSV) text file. WorkArray = Multi_Dimension("C:\Temp\~JobFileCSV~.csv",",") ' Ascertain the number of rows and columns in the multidimensional ' array. TotalRows and TotalColumns variables represent the ' upper bounds of both the rows and columns, which are used to ' enumerate all values within the array. TotalRows = UBound(WorkArray) TotalColumns = UBound(WorkArray,2) ' Enumerate the values contained in the multidimensional array. For Row = 0 To TotalRows outPutString = "Row" & Row ' Display the row and column data. For Col = 0 To TotalColumns outPutString = outPutString & vbCrLf & " Column" & Col & " = " _ & WorkArray(Row,Col) & " " Next MsgBox outPutString Next ' ******* BEGIN CALLOUT A ******* Function Multi_Dimension(Filename,Delim) On Error Resume Next ' Check for the data file and open it if it exists. ' Terminate the script if the file doesn't exist. Const ForReading = 1 ' ******* END CALLOUT A ******* ' ******* BEGIN CALLOUT B ******* Set fso = CreateObject("Scripting.FileSystemObject") If NOT fso.FileExists(Filename) Then Msgbox "Text file does not exist... Terminating program." Set fso = Nothing WScript.Quit End If Set txtfile = fso.OpenTextFile(FileName,ForReading,False) ' Read the entire text file into a storage variable. textData = txtfile.ReadAll ' ******* END CALLOUT B ******* ' ******* BEGIN CALLOUT C ******* ' Remove the last carriage return if one exists and close the text file. If Asc(Right(textData,1)) = 10 Then textData = Left(textData,Len(textData)-1) End If ' ******* END CALLOUT C ******* txtfile.Close ' ******* BEGIN CALLOUT D ******* ' Create an array that contains the rows from the text file. textDataArray = Split(textData,vbCrLf) ' ******* END CALLOUT D ******* ' ******* BEGIN CALLOUT E ******* ' Initialize the multidimensional array. Dim BuildArray() ' Determine the dimensions of the multidimensional array. TotalRows = UBound(textDataArray) TotalColumns = UBound(Split(textDataArray(0),Delim)) ' Redimension the multidimensional array to the proper size. ReDim BuildArray(TotalRows,TotalColumns) ' ******* END CALLOUT E ******* ' ******* BEGIN CALLOUT F ******* ' Build the multidimensional array one row and one column at a time. ' Split each element of the textData array (based on the delimiter ' passed in) into temporary arrays. These become the columns of each row. For Row = 0 To TotalRows TempArray = "" TempArray = Split(textDataArray(Row),Delim) For Col = 0 To TotalColumns BuildArray(Row,Col) = TempArray(Col) Next Next ' ******* END CALLOUT F ******* ' ******* BEGIN CALLOUT G ******* ' Return the multidimensional array. Multi_Dimension = BuildArray ' ******* END CALLOUT G ******* Set fso = Nothing Set txtfile = Nothing End Function