Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - I NEED HELP creating a multidimensional array from a csv file

Reply
 
Old 06-30-2009   #1 (permalink)
Christopher


 
 

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
'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

Loop
End Sub 'Main Routine

I am receiving a subscript out of range message

My System SpecsSystem Spec
Old 07-01-2009   #2 (permalink)
ekkehard.horner


 
 

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
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
My System SpecsSystem Spec
Old 07-18-2009   #3 (permalink)
Al Dunbar


 
 

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
Another issue is the definition of the "delimiter" variable. The delimiter
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 SpecsSystem Spec
Old 07-26-2009   #4 (permalink)
Richard.Williams.20


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46