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

bad file mode error

Status
Not open for further replies.

abhayrao

Technical User
Nov 5, 2002
16
0
0
IN
iam a beginner.please explain how to deal with the `bad file mode` error which i encountered while trying to write text to a file in VBscript.
 
here is my code.You wanted to see it fengshui_1998 :-
<html>
<script language=&quot;VBScript&quot;>
function save()
Dim oFS, writefile
Set oFS = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set writefile= oFS.OpenTextFile(&quot;c:\a.txt&quot;,true)
writefile.write(S1.value)
writefile.close
end function
function open()
Dim oFS, readfile
Set oFS = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set readfile= oFS.OpenTextFile(&quot;c:\a.txt&quot;,true)
readfile.ReadAll
readfile.close
end function
</script>
<body>
<textarea rows=&quot;20&quot; name=&quot;S1&quot;
cols=&quot;80&quot;></textarea><br>
<input type=&quot;button&quot; id=&quot;save&quot;
value=&quot;Save&quot; onClick=&quot;save()&quot;>
<input type=&quot;button&quot; id=&quot;open&quot;
value=&quot;Open&quot; onClick=&quot;open()&quot;>
</body>
</html>
 
here is my code.You wanted to see it fengshui_1998 :-
<html>
<script language=&quot;VBScript&quot;>
function save()
Dim oFS, writefile
Set oFS = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set writefile= oFS.OpenTextFile(&quot;c:\a.txt&quot;,true)
writefile.write(S1.value)
writefile.close
end function
function open()
Dim oFS, readfile
Set oFS = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set readfile= oFS.OpenTextFile(&quot;c:\a.txt&quot;,true)
readfile.ReadAll
readfile.close
end function
</script>
<body>
<textarea rows=&quot;20&quot; name=&quot;S1&quot;
cols=&quot;80&quot;></textarea><br>
<input type=&quot;button&quot; id=&quot;save&quot;
value=&quot;Save&quot; onClick=&quot;save()&quot;>
<input type=&quot;button&quot; id=&quot;open&quot;
value=&quot;Open&quot; onClick=&quot;open()&quot;>
</body>
</html>
 
Dear abhyrao,
You should replace thecode bellow instead of line 6 in your code(OpenTextFile):

Set writefile= oFS.OpenTextFile(&quot;c:\a.txt&quot;,2,true)
Behnam2204@yahoo.com
BehnamPro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top