Code 800A0005 when using set objFile = objFSO.OpenTextFile

I have repeatedly searched for this error code and went to numerous sites to read the answers. In short, no solution has yet been found.

One page link: Error sending (character using sendkeys in vbscript

Here is my code:

set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("C:\Downloads\software\putty.exe -load navstat")

DIM date 
date = 301113

DIM tran1
tran1 = TAFFY

set objFSO = CreateObject("Scripting.FileSystemObject") 
set objFile = objFSO.OpenTextFile("C:\Users\Adrian\Desktop\Entries1.txt", ForReading) 

Do Until objFile.AtEndOfStream 
    strLine = objFile.ReadLine 
    If InStr(strLine, "JFK.GREKI3.MARTN..TOPPS") Then 
        set indi = 2 
        set tran1 = TOPPS 
    End If
Loop

What happens: I am looking at a .txt file (Entries1.txt) for text strings. If they arise, I need to set the appropriate indi values ​​(so when indi is used later as a variable, it will use the correct #) and will also change the tran1 variables.

For some reason, I get an error:

set objFile = objFSO.OpenTextFile

Mistake

Invalid call or procedure argument Code: 800A0005

Help would be greatly appreciated.

+4
2

ForReading , :

'Saved in D:\TempFiles\TypeFile.vbs
set objFSO = CreateObject("Scripting.FileSystemObject") 
set objFile = objFSO.OpenTextFile("C:\Users\Ken\Desktop\Test.txt") 

Do Until objFile.AtEndOfStream 
    strLine = objFile.ReadLine 
    wscript.echo strLine
Loop

Test.txt, :

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6

, :

D:\TempFiles>cscript TypeFile.vbs

:

enter image description here

. , , set (, , ):

set indi = 2

indi - , , set. :

indi = 2
+2

Ken , , , .

ForReading

set objFile = objFSO.OpenTextFile("C:\Users\Adrian\Desktop\Entries1.txt", ForReading)

OpenTextFile iomode, 1, 2 8. , , , . ( ), . :

Const ForReading   = 1
Const ForWriting   = 2
Const ForAppending = 8

( 1).

undefined ForReading, Empty, , .

:

>>> WScript.Echo TypeName(ForReading)
Empty
>>> Set f = fso.OpenTextFile("C:\Temp\some.txt", ForReading)
Invalid procedure call or argument (0x5)
>>> WScript.Echo TypeName(f)
Empty
>>> Set f = fso.OpenTextFile("C:\Temp\some.txt", Empty)
Invalid procedure call or argument (0x5)
>>> WScript.Echo TypeName(f)
Empty
>>> 'parameter omitted
>>> Set f = fso.OpenTextFile("C:\Temp\some.txt")
>>> WScript.Echo TypeName(f)
TextStream
>>> Set f = Nothing
>>> 'numeric parameter
>>> Set f = fso.OpenTextFile("C:\Temp\some.txt", 1)
>>> WScript.Echo TypeName(f)
TextStream
>>> Set f = Nothing
>>> 'define identifier before using it as parameter
>>> ForReading = 1
>>> WScript.Echo TypeName(ForReading)
Integer
>>> Set f = fso.OpenTextFile("C:\Temp\some.txt", ForReading)
>>> WScript.Echo TypeName(f)
TextStream

, Option Explicit ( ). , undefined, , .

+10

All Articles