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
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