Re: Parsing .CSV files - no luck whatsoever
From: Jerold Schulman (Jerry_at_jsiinc.com)
Date: 03/07/05
- Next message: nobelium: "Re: Shell.localmachine error 800A01AD"
- Previous message: Torgeir Bakken \(MVP\): "Re: Parts of an URL"
- In reply to: Jason: "Parsing .CSV files - no luck whatsoever"
- Next in thread: Jason: "Re: Parsing .CSV files - no luck whatsoever"
- Reply: Jason: "Re: Parsing .CSV files - no luck whatsoever"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 07 Mar 2005 13:40:57 -0500
On Mon, 07 Mar 2005 10:15:24 -0800, Jason <shift838@y---o.com> wrote:
>As a VBScript newbie I am unable to successfully parse a .CSV plain text
>file using VBScript depite cutting and pasting sample scripts from two
>Microsoft scripting books and one from their Script Repository. It keeps
>throwing "Subscript out of range" errors or empty returns. I've tried using
>a plain text .CSV file from Notepad that looks like this:
>
>test1,test2,test3
>test4,test5,test6
>
>And I've tried exporting event logs as .CSV files. For example, the script
>at this link:
>http://www.microsoft.com/technet/scriptcenter/scripts/logs/text/lgtxvb01.ms
>px
>
>..generates this error "Subscript out of range: '[number: 3]'" when run
>against my Notepad CSV.
>
>What am I missing here? Can all three sample scripts be buggy or should I
>stick to NT shell scripting (which I had no trouble making read a CSV file
>in just a couple of lines)???
I am a newbie VBScripter also.
Use cscript //nolog split.vbs Notepad.csv
where split.vbs contains:
Set objArguments = Wscript.Arguments
iFile=objArguments(0)
set fso = CreateObject("Scripting.FileSystemObject")
set rfile = fso.OpenTextFile(iFile, 1, false)
Do until rFile.AtEndOfStream = True
iString = rFile.ReadLine
oString = split(iString, ",")
Wscript.Echo oString(0)
Wscript.Echo oString(1)
Wscript.Echo oString(2)
loop
rFile.close
Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
- Next message: nobelium: "Re: Shell.localmachine error 800A01AD"
- Previous message: Torgeir Bakken \(MVP\): "Re: Parts of an URL"
- In reply to: Jason: "Parsing .CSV files - no luck whatsoever"
- Next in thread: Jason: "Re: Parsing .CSV files - no luck whatsoever"
- Reply: Jason: "Re: Parsing .CSV files - no luck whatsoever"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|