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

Object Expected when Writing to a File.

Status
Not open for further replies.

TRHorn

Technical User
Feb 21, 2010
24
US
function WriteFile()
{
var fh = fopen("c:\\MyFile.txt", 3);
if(fh!=-1)
{
var str = "Some text goes here...";
fwrite(fh, str);
fclose(fh);
}
}
WriteFile();

I am getting an error that says line 3 char 5 object expected.

I'm new to JS I don't know much about FSO manipulation. I'm sure it's an easy problem thanks for any help in advance.
 
Correction error is line 3 char 2.
 
I thought you'd something of php in mind (fopen etc...) until I saw your reference to fso. If you've actually wsh script in mind, this is how it looks like.
[tt]
function WriteFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ots=fso_OpenTextFile("c:\\MyFile.txt",2,true);
var ots=fso_OpenTextFile("g00965a_out.txt",2,true);
var str = "Some text goes here...";
ots.Write(str);
ots.Close();
ots=null;
fso=null;
}
WriteFile();
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top