From: Bill on 23 Jul 2010 16:24 I have a script that cleans up dates in a text file, and normally works well but sometimes the text file contains text the script cant deal with and it errors out. How would i go about telling the script to ignore lines with the word Now in it (see examples below)? Here's the script: Set fso = CreateObject("Scripting.FileSystemObject") Set inF = fso.OpenTextFile("C:\IM\processing.txt", 1) Set outF = fso.OpenTextFile("C:\IM\upload.txt", 2, True) Function Pad (n) Pad = Right("0" & n, 2) End Function Do Until inF.AtEndOfStream sLine = inF.ReadLine Do While InStr(sLine, " ") > 0 sLine = Replace(sLine, " ", " ") Loop aLine = Split(sLine) sKey = Replace(aLine(0), "L3", "", 1, - 1, 1) & " " dDate = CDate(aLine(1) & " " & aLine(2) & " " & aLine(3)) outF.WriteLine sKey & Pad(Month(dDate)) & Pad(Day(dDate)) & Year(dDate) Loop And usually the input looks like this: AA1759L3 Jul 17 2015 4:00AM But sometimes it will look like this: AA1423L3 Now and thats when I get this error: normalize.vbs(16, 3) Microsoft VBScript runtime error: Subscript out of range: '[number: 2]' And really I just want the script to skip that line. Any help is much appreciated.
From: Mayayana on 23 Jul 2010 17:08 Something like this, maybe? Do Until inF.AtEndOfStream sLine = inF.ReadLine If Instr(1, sLine, "Now", 1) = 0 then sLine = Replace(sLine, " ", " ") aLine = Split(sLine, " ") sKey = Replace(aLine(0), "L3", "", 1, - 1, 1) & " " dDate = CDate(aLine(1) & " " & aLine(2) & " " & aLine(3)) outF.WriteLine sKey & Pad(Month(dDate)) & Pad(Day(dDate)) & Year(dDate) End If Loop
From: Bill on 26 Jul 2010 12:50 Awesome, thanks for your help! "Mayayana" wrote: > Something like this, maybe? > > Do Until inF.AtEndOfStream > sLine = inF.ReadLine > If Instr(1, sLine, "Now", 1) = 0 then > sLine = Replace(sLine, " ", " ") > aLine = Split(sLine, " ") > sKey = Replace(aLine(0), "L3", "", 1, - 1, 1) & " " > dDate = CDate(aLine(1) & " " & aLine(2) & " " & aLine(3)) > outF.WriteLine sKey & Pad(Month(dDate)) & Pad(Day(dDate)) & Year(dDate) > End If > Loop > > > > . >
|
Pages: 1 Prev: I GOT $2000 FROM PAYPAL . Next: I GOT $1000 FROM PAYPAL WITH SMALL HACK. |