Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

End of File

Status
Not open for further replies.

bob120579

Programmer
Feb 9, 2005
42
0
0
US
I have an ActiveX script where I am reading a text file into a variable through an FSO. I have to loop through to check each record's length. The problem is my condition on the loop when i check for end of file. I know when you use a recordset, you can say when the object eof, but i'm not sure how to check for end of file when using a variable and FSO. The only part giving me an error is the "do while not x.eof". Any help would be greatly appreciated. Here is the code:


Function Main()

dim oFSO
dim x,y
dim vRecord
dim slength,sState,sZip,sAccount,sErrorLog,ErrorCount,ErrorFlag

' Instantiate the Scripting Object
set oFSO = CreateObject("Scripting.FileSystemObject")

' Open the file
set x = oFSO.OpenTextFile("\\10.0.5.50\files\ftp\LMNR217M.P0217.txt")

' Read the first line, which is the Header record
x.Readline
y = 1

'** start checking each row in the file ****
''****** Now loop through the file and check each row

do while not x.eof ' do until EOF
vrecord = x.Readline
slength = len(trim(vRecord))
'***** check Record Length *************

if sLength > 108 then
'msgbox("Length not good " & sTel1)
sErrorLog = sErrorLog + "Invalid Record Length : " & sLength & " Must be 104 or 108 characters" & VbCrLf
ErrorFlag = 1
end if

'**Check error flag
if ErrorFlag = 1 then
sErrorLog = sErrorLog + vRecord
ErrorCount = ErrorCount + 1
End If

'msgbox(sSex & sState & sZip & sTel1 & sTel2 & sDate & sCode)

ErrorFlag = 0
'**Record Count
y = y + 1
loop


x.Close

Main = DTSTaskExecResult_Success

End Function
 
I actually found the answer...here it is in case anyone is interested....

I just altered the Do...Loop statement to:

do while x.AtEndOfStream = False
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top