![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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) 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 Specs![]() |
| | #3 (permalink) |
| | 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). 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 Specs![]() |
![]() |
| 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 | |||