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 - retrieve text within an array

Reply
 
Old 10-03-2008   #1 (permalink)
yeleek


 
 

retrieve text within an array

Hi,

Some of logs come to me in CSV format. I'd like to use vbscript to
filter these logs and present only the helpful info. The item strmsg
contains a message, within that message are the user name, domain,
error etc. I've tried to use a further split on strmsg and get it to
then wscript.echo the 11th word (the user name) but it won't tells me
'Subscript out of range: '[number: 11]'' (there are far more than 11
words seperated by spaces). Tell it to use word 0 or 1 and it works
fine.

Please help - am i using the wrong code?

dim fs,objTextFile
set fs=CreateObject("Scripting.FileSystemObject")
dim arrStr
set objTextFile = fs.OpenTextFile("021008.csv")

Do while NOT objTextFile.AtEndOfStream
arrStr = split(objTextFile.ReadLine,",")
strdatetime = arrStr(0)
strviewname = arrStr(1)
strdevice = arrStr(2)
streventid = arrStr(3)
strmsg = arrStr(4)
strorigip = arrStr(5)
strsourceip = arrStr(6)
strdestip = arrStr(7)

strusername=split(strmsg)
wscript.echo (strusername(11))
' arrStr is now an array that has each of your fields
'wscript.echo strdatetime & " " & streventid
Loop

objTextFile.Close
set objTextFile = Nothing
set fs = Nothing

My System SpecsSystem Spec
Old 10-03-2008   #2 (permalink)
Tom Lavedas


 
 

Re: retrieve text within an array

On Oct 3, 9:43*am, yel...@xxxxxx wrote:
Quote:

> Hi,
>
> Some of logs come to me in CSV format. *I'd like to use vbscript to
> filter these logs and present only the helpful info. *The item strmsg
> contains a message, within that message are the user name, domain,
> error etc. *I've tried to use a further split on strmsg and get it to
> then wscript.echo the 11th word (the user name) but it won't tells me
> 'Subscript out of range: '[number: 11]'' (there are far more than 11
> words seperated by spaces). *Tell it to use word 0 or 1 and it works
> fine.
>
> Please help - am i using the wrong code?
>
> dim fs,objTextFile
> set fs=CreateObject("Scripting.FileSystemObject")
> dim arrStr
> set objTextFile = fs.OpenTextFile("021008.csv")
>
> Do while NOT objTextFile.AtEndOfStream
> * arrStr = split(objTextFile.ReadLine,",")
> * strdatetime = arrStr(0)
Need to see the content of one line data to diagnose it for sure,
however I note that you say the it has "far more than 11 words
seperated [sic] by spaces", but your Split uses a comma not a space as
its separation character. Therefore, it appears the line has only one
comma.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
My System SpecsSystem Spec
Old 10-03-2008   #3 (permalink)
mayayana


 
 

Re: retrieve text within an array

>
Quote:

> Some of logs come to me in CSV format. I'd like to use vbscript to
> filter these logs and present only the helpful info. The item strmsg
> contains a message, within that message are the user name, domain,
> error etc. I've tried to use a further split on strmsg and get it to
> then wscript.echo the 11th word (the user name) but it won't tells me
> 'Subscript out of range: '[number: 11]''
Quote:

> (there are far more than 11
> words seperated by spaces).
Spaces or commas? Your code is splitting on
commas.

If you don't have Array(11) then there were not
11+ commas in the line. Maybe you have a blank
line? If you have some sort of strange format that
could include Chr(0) that would also affect your line.
You might try tracking the exact line where you first
get the error, so you can see what that is.

Trying to compact your code also doesn't help:

arrStr = split(objTextFile.ReadLine,",")

You've crammed 2 operations together with no chance
to check the line. If it turns out that you want/need
error checking it might be better to do something like:

s = objTextFile.ReadLine
If Len(s) > 3 Then '-- or other relevant number.
arrStr = Split(s, ",")
...etc...
Quote:

> Tell it to use word 0 or 1 and it works
> fine.
>
> Please help - am i using the wrong code?
>
> dim fs,objTextFile
> set fs=CreateObject("Scripting.FileSystemObject")
> dim arrStr
> set objTextFile = fs.OpenTextFile("021008.csv")
>
> Do while NOT objTextFile.AtEndOfStream
> arrStr = split(objTextFile.ReadLine,",")
> strdatetime = arrStr(0)
> strviewname = arrStr(1)
> strdevice = arrStr(2)
> streventid = arrStr(3)
> strmsg = arrStr(4)
> strorigip = arrStr(5)
> strsourceip = arrStr(6)
> strdestip = arrStr(7)
>
> strusername=split(strmsg)
> wscript.echo (strusername(11))
> ' arrStr is now an array that has each of your fields
> 'wscript.echo strdatetime & " " & streventid
> Loop
>
> objTextFile.Close
> set objTextFile = Nothing
> set fs = Nothing

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
how to retrieve an array returned from stored procedure VB Script
How do i retrieve only the values from array ? PowerShell
Re: loop through text and create array PowerShell
How do I retrieve text from Clipboard? Vista General
how to assign values to array and how to create array via variable 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