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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

objFSO.OpenTextFile won't accept 4 arguments !? 1

Status
Not open for further replies.

Geates

Programmer
Aug 25, 2009
1,566
US
Code:
set objFSO = CreateObject("Scripting.FileSystemObject")

'Generates an "Invalid procedure call or argument" error
set objStream = objFSO.OpenTextFile("C:\file.txt", 1, true, 1)

'Does not generate an error
set objStream = objFSO.OpenTextFile("C:\file.txt", 1, 1)

What gives?

-Geates

 
I guess OpenTextFile does not look for a "create" argument if the "iomode" argument is 1 (ForReading).

Not tested but i would assume that both:
set objStream = objFSO.OpenTextFile("C:\file.txt", [highlight #FCE94F]2[/highlight], true, 1)
and
set objStream = objFSO.OpenTextFile("C:\file.txt", [highlight #FCE94F]8[/highlight], true, 1)
would work
 
It's the format.

'Generates an "Invalid procedure call or argument" error
set objStream = objFSO.OpenTextFile("C:\file.txt", 1, true, 1)

'Does not generate an error
set objStream = objFSO.OpenTextFile("C:\file.txt", 1, true, 0)

This means I've never opened a file as unicode :)

-Geates

 
there is no tristate value of 1!
Code:
Constant Value Description 
TristateUseDefault –2 Opens the file using the system default. 
TristateTrue       –1 Opens the file as Unicode. 
TristateFalse       0 Opens the file as ASCII.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Ahh... I didn't look at the link I posted carefully enough, I missed that tristate values are only -1, 0 and -2. Replacing the magic numbers with constant definitions at the top of the script would solve that problem :)
 
It's the little things that matter.
Nicely spotted, Skip!
[thumbsup2]

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top