Thursday, December 10, 2015

Known errors while reading the Text file with the use of File System Object

1. Some time we face the error as "Bad file mode" while reading the text file from the particular location. if we execute the below code than this error will generate.

filename = "D:\Test.txt"
strmode = 2
Set o1 = Createobject("Scripting.Filesystemobject")
If o1.FileExists(filename) = true Then
    set r1 = o1.OpenTextFile (filename,strmode)
 else
    ExitTest
End If
Msgbox r1.readall()


Above error is generated because of invalid file mode while reading the file,becuase in above code we selected the mode as 2 and it means this text file is open in write mode.
To avoid this error we have to open the text in to the read mode i.e "1"


2. Some time we face the error as "Input past end of file" .while reading the text from the notepad file.

Above error is generated when we try to read the empty notepad file.


No comments:

Post a Comment