mmitchell57
asked on
VBScript, FileSystemObject, AtEndOfString Problems
Hello,
I am sure this is something simple, but I haven't done this type of stuff in quite some time. I am trying to open one file, read it, put line by line info into an array. Then, I want to clean up the data and dump it to a new file. The code I am including is my basic's that i'm starting with. I cannot get the "f = fso.OpenTextFile" to cooperate at all. If I try to add the "ReadOnly, True" arguments, I get errors. The "f.AtEndOfString" doesn't appear to be working either. Please offer some direction to get me going a bit further. I appreicate everything.
As a note, I'm using VBScripting. I would like to stay with that if at all possible. The originating data file is a txt file.
I am sure this is something simple, but I haven't done this type of stuff in quite some time. I am trying to open one file, read it, put line by line info into an array. Then, I want to clean up the data and dump it to a new file. The code I am including is my basic's that i'm starting with. I cannot get the "f = fso.OpenTextFile" to cooperate at all. If I try to add the "ReadOnly, True" arguments, I get errors. The "f.AtEndOfString" doesn't appear to be working either. Please offer some direction to get me going a bit further. I appreicate everything.
As a note, I'm using VBScripting. I would like to stay with that if at all possible. The originating data file is a txt file.
Dim fso, f, f2, lineNum(), cnt, i, ii
ii = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\temp.txt")
Do while not f.AtEndOfString
ReDim Preserve lineNum(ii)
lineNum(ii) = ii
ii = ii + 1
Loop
f.Close
Set f2 = fso.CreateTextFile("C:\disabled.cvs")
For each i in lineNum
f2.WriteLine lineNum(i)
Next
f2.Close
Set f = Nothing
Set f2 = Nothing
Set fso = Nothing
ASKER
Ok, i've mad it this far in the code. I now get an error message stating "Subscript out of range: "12"...
here's the code that's updated.
here's the code that's updated.
Dim fso, f, f2, ts, lineNum(), cnt, i, ii
ii = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\temp.txt", 1, true)
Do until ii = 10
ReDim Preserve lineNum(ii)
lineNum(ii) = f.readline
ii = ii + 1
Loop
f.Close
Set f2 = fso.CreateTextFile("C:\disabled.cvs")
For each i in lineNum
f2.WriteLine lineNum(i)
Next
f2.Close
Set f = Nothing
Set f2 = Nothing
Set fso = Nothing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent answer. :) I appreciate the info and help!
No problem. Thanks for the grade.
Regards,
Rob.
Regards,
Rob.
ASKER