![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | I NEED HELP creating a multidimensional array from a csv file Here is what I have: Dim List,EmailServer,ToAddress,strComputer,Logfile,Domain,Sendto Set WshShell = WScript.CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Set colNamedArguments = WScript.Arguments.Named List = colNamedArguments.item("Serverlist") EmailServer = colNamedArguments.item("SMTPServer") strLogfile = colNamedArguments.item("Log") Sendto = colNamedArguments.item("ToAddress") MainRoutine ParseToAddress 'Notification Sub MainRoutine Dim fServers, arrLogFile, strStatus,strTaskname,strNextRunTime,strlogline,delimeter delimeter= (chr(34) & "," & chr(34)) Set fServers = objFSO.OpenTextFile(List , 1, True) Do While Not fServers.AtEndOfStream strComputer = Trim(fServers.Readline) 'Create Log Files WshShell.Run "cmd /c echo." & " >> " & strLogfile WshShell.Run "cmd /c echo " & Date & " " & Time & " " & strComputer & " >> " & strLogfile WshShell.Run "cmd /c schtasks /query /FO csv /s " & strComputer & " Quote: Quote: >> " & strLogfile set objTextFile = objFSO.OpenTextFile(strLogfile,1,True) Do while NOT objTextFile.AtEndOfStream strlogline=(objTextFile.ReadLine) arrlogfile = split(strLogline,delimeter) ' arrStr is now an array that has each of your fields strTaskname = arrlogfile(0) strNextRunTime = arrlogfile(1) strStatus = arrlogfile(2) WScript.Echo strTaskname & " " & strNextRunTime & " " &strStatus Loop Loop End Sub 'Main Routine I am receiving a subscript out of range message |
My System Specs![]() |
| | #2 (permalink) |
| | Re: I NEED HELP creating a multidimensional array from a csv file Christopher schrieb: Quote: > Here is what I have: > > Dim List,EmailServer,ToAddress,strComputer,Logfile,Domain,Sendto Quote: > 'Parse the log file > set objTextFile = objFSO.OpenTextFile(strLogfile,1,True) > Do while NOT objTextFile.AtEndOfStream > strlogline=(objTextFile.ReadLine) > arrlogfile = split(strLogline,delimeter) > ' arrStr is now an array that has each of your fields > strTaskname = arrlogfile(0) > strNextRunTime = arrlogfile(1) > strStatus = arrlogfile(2) > WScript.Echo strTaskname & " " & strNextRunTime & " " &strStatus > Loop Quote: > I am receiving a subscript out of range message set objTextFile = objFSO.OpenTextFile(strLogfile,1,True) Do Until objTextFile.AtEndOfStream strlogline=Trim(objTextFile.ReadLine) If "" <> strlogline Then arrlogfile = split(strLogline,delimeter) ' arrStr (lying in comment!) is now an array that has each of your fields If 2 = UBound( arrlogfile ) Then strTaskname = arrlogfile(0) strNextRunTime = arrlogfile(1) strStatus = arrlogfile(2) WScript.Echo Join( arrlogfile, " " ) Else WScript.Echo "?", Join( arrlogfile, "|" ) End If Else WScript.Echo "?", "empty line" End If Loop |
My System Specs![]() |
| | #3 (permalink) |
| | Re: I NEED HELP creating a multidimensional array from a csv file "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message news:4a4b07d3$0$31879$9b4e6d93@xxxxxx-online.net... Quote: > Christopher schrieb: Quote: >> Here is what I have: >> >> Dim List,EmailServer,ToAddress,strComputer,Logfile,Domain,Sendto Quote: >> 'Parse the log file >> set objTextFile = objFSO.OpenTextFile(strLogfile,1,True) >> Do while NOT objTextFile.AtEndOfStream >> strlogline=(objTextFile.ReadLine) >> arrlogfile = split(strLogline,delimeter) >> ' arrStr is now an array that has each of your fields >> strTaskname = arrlogfile(0) >> strNextRunTime = arrlogfile(1) >> strStatus = arrlogfile(2) >> WScript.Echo strTaskname & " " & strNextRunTime & " " &strStatus >> Loop Quote: >> I am receiving a subscript out of range message > Check your assumptions: > > set objTextFile = objFSO.OpenTextFile(strLogfile,1,True) > Do Until objTextFile.AtEndOfStream > strlogline=Trim(objTextFile.ReadLine) > If "" <> strlogline Then > arrlogfile = split(strLogline,delimeter) > ' arrStr (lying in comment!) is now an array that has each of your > fields > If 2 = UBound( arrlogfile ) Then > strTaskname = arrlogfile(0) > strNextRunTime = arrlogfile(1) > strStatus = arrlogfile(2) > WScript.Echo Join( arrlogfile, " " ) > Else > WScript.Echo "?", Join( arrlogfile, "|" ) > End If > Else > WScript.Echo "?", "empty line" > End If > Loop in a .csv file is just a comma, not a comma in quotes. Try changing this: delimeter= (chr(34) & "," & chr(34)) to this: delimeter= "," Of course, you will often see commas in a csv that appear to be surrounded by quotes. In reality, though, it is the individual elements that are quoted. For example: "one","two","three" If you use ["."] as the delimiter, then the second element is [two], which looks OK, but the first is ["one]. If you have quoted elements, you should use a comma delimiter, and strip the quotes from the elements later. /Al |
My System Specs![]() |
| | #4 (permalink) |
| | Re: I NEED HELP creating a multidimensional array from a csv file To parse a .CSV (comma separated values) or a .TSV (tab separated values), there is a good sample script posted at http://www.biterscripting.com/SS_CSV.html .. Richard |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Is there a simple way to search a multidimensional array? | PowerShell | |||
| Re: Creating array | PowerShell | |||
| Re: Creating array | PowerShell | |||
| multidimensional array initialization | PowerShell | |||
| Creating an array | PowerShell | |||