I have the following code where I am trying to write a
header in file. I am getting some crap in new file. Please
help me.
Const ForWriting = 2
Dim fso, theFile
strDate = Year(Date) & Right("0"&Month(Date),2) & Right
("0"&Day(Date),2)
Set fso = CreateObject("Scripting.FileSystemObject")
rootDir="C:\"
Set theFile1 = fso.createTextFile("C:\Header.txt",
ForWriting, True)
theFile1.writeline "HST" & strDate
theFile1.Close
FileSpec1 = "C:\Header.txt"
sFileSpec2 = "C:\test.txt"
With CreateObject("Scripting.FileSystemObject")
set f1 = .OpenTextFile(sFileSpec1, 8)
f1.Write .OpentextFile(sFileSpec2, 1).ReadAll
f1.Close
End With

Re: File by Ray

Ray
Thu Aug 28 09:14:33 CDT 2003

Perhaps an explanation a little better than "getting some crap" would help
us understand what isn't working for you.

Ray at work

"sardinka" <sardinka2@yahoo.com> wrote in message
news:0e3001c36d6a$5923b860$a301280a@phx.gbl...
> I have the following code where I am trying to write a
> header in file. I am getting some crap in new file. Please
> help me.
> Const ForWriting = 2
> Dim fso, theFile
> strDate = Year(Date) & Right("0"&Month(Date),2) & Right
> ("0"&Day(Date),2)
> Set fso = CreateObject("Scripting.FileSystemObject")
> rootDir="C:\"
> Set theFile1 = fso.createTextFile("C:\Header.txt",
> ForWriting, True)
> theFile1.writeline "HST" & strDate
> theFile1.Close
> FileSpec1 = "C:\Header.txt"
> sFileSpec2 = "C:\test.txt"
> With CreateObject("Scripting.FileSystemObject")
> set f1 = .OpenTextFile(sFileSpec1, 8)
> f1.Write .OpentextFile(sFileSpec2, 1).ReadAll
> f1.Close
> End With
>



Re: File by sardinka

sardinka
Thu Aug 28 09:54:48 CDT 2003

That is what I am getting in file:
?????&#12320;&#12848;&#12855;&#12592;&#12595;&#27714;&#25973;&#29251;&#29=
551;&#8307;&#27714;&#25973;&#26707;&#25961;&#25708;????????????????????&#=
22616;&#13648;&#13618;&#12595;&#12600;&#14649;
&#12576;&#8241;??&#30032;&#28276;&#28001;????????&#12832;&#12336;&#12339;=
&#12856;`?????&#24919;&#30313;&#25701;?&#8270;&#19488;&#21833;???????????=
??&#18976;

Re: File by Tom

Tom
Thu Aug 28 14:41:32 CDT 2003

Your original posted script has an error in its use of the=20
fso.createTextFile method. That method does NOT take a=20
ForWriting parameter as you used and the third parameter=20
is for specifying whether the file is to store Unicode or=20
ASCII. Your script had the Unicode parameter set as True,=20
but you later reopen it as ASCII (ANSI). This error is=20
causing the garbling. Either change this line

Set theFile1 =3D fso.createTextFile("C:\Header.txt", _
ForWriting, True)

to=20

Set theFile1 =3D fso.createTextFile("C:\Header.txt", _
True, False)

Or switch to the OpenTextFile method

Set theFile1 =3D fso.OpenTextFile("C:\Header.txt", _
ForWriting, True)

which is probably what you had in mind, originally.

BTW, you don't need to close it and reopen it for=20
appending. You can just add to the file in subsequent=20
writes, since it's all happening in on process. That=20
is, ...

Const ForReading, ForWriting =3D 2
Dim fso, f1, strDate, rootDir, sFileSpec1, sFileSpec2=20
strDate =3D Year(Date) & Right("0"&Month(Date),2) _
& Right("0"&Day(Date),2)=20
rootDir =3D "C:\"
sFileSpec1 =3D rootDir & "Header.txt"
sFileSpec2 =3D rootDir & "test.txt"
With CreateObject("Scripting.FileSystemObject")
set f1 =3D .OpenTextFile(sFileSpec1, ForWriting)
f1.writeline "HST" & strDate
f1.Write .OpentextFile(sFileSpec2, ForReading).ReadAll
f1.Close
End With

I believe all the rest is redundant.

Tom Lavedas
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

>-----Original Message-----
>That is what I am getting in file:
>?????&#12320;&#12848;&#12855;&#12592;&#12595;&#27714;&#25973;&#29251;&#2=
9551;&#8307;&#27714;&#25973;&#26707;&#25961;&#25708;????????????????????&=
#22616;&#13648;&#13618;&#12595;&#12600;
&#14649;
>&#12576;&#8241;??&#30032;&#28276;&#28001;????????&#12832;&#12336;&#12339=
;&#12856;`?????&#24919;&#30313;&#25701;?&#8270;&#19488;&#21833;??????????=
???&#18976;
>.
>

Re: File by Aaron

Aaron
Thu Aug 28 21:09:56 CDT 2003

Sardinka, your original file "test.txt" is in unicode wide format. If you
open it in a hex editor you will see every other byte is nulls except where
extended Non ascii characters are present, eg a non Western Eoropean English
or US English region. FSO defaults to pening as US Ascii.

Description
Opens a specified file and returns a TextStream object that can be used to
read from, write to, or append to the file.
Syntax
object.OpenAsTextStream([iomode, [format]])
The OpenAsTextStream method syntax has these parts:

Part Description
object Required. Always the name of a File object.
iomode Optional. Indicates input/output mode. Can be one of three
constants: ForReading, ForWriting, or ForAppending.
format Optional. One of three Tristate values used to indicate the
format of the opened file. If omitted, the file is opened as ASCII.




The format argument can have any of the following settings:

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.




"Tom Lavedas" <tlavedas@hotmail.com> wrote in message
news:040701c36d9c$61f2e560$a301280a@phx.gbl...
Your original posted script has an error in its use of the
fso.createTextFile method. That method does NOT take a
ForWriting parameter as you used and the third parameter
is for specifying whether the file is to store Unicode or
ASCII. Your script had the Unicode parameter set as True,
but you later reopen it as ASCII (ANSI). This error is
causing the garbling. Either change this line

Set theFile1 = fso.createTextFile("C:\Header.txt", _
ForWriting, True)

to

Set theFile1 = fso.createTextFile("C:\Header.txt", _
True, False)

Or switch to the OpenTextFile method

Set theFile1 = fso.OpenTextFile("C:\Header.txt", _
ForWriting, True)

which is probably what you had in mind, originally.

BTW, you don't need to close it and reopen it for
appending. You can just add to the file in subsequent
writes, since it's all happening in on process. That
is, ...

Const ForReading, ForWriting = 2
Dim fso, f1, strDate, rootDir, sFileSpec1, sFileSpec2
strDate = Year(Date) & Right("0"&Month(Date),2) _
& Right("0"&Day(Date),2)
rootDir = "C:\"
sFileSpec1 = rootDir & "Header.txt"
sFileSpec2 = rootDir & "test.txt"
With CreateObject("Scripting.FileSystemObject")
set f1 = .OpenTextFile(sFileSpec1, ForWriting)
f1.writeline "HST" & strDate
f1.Write .OpentextFile(sFileSpec2, ForReading).ReadAll
f1.Close
End With

I believe all the rest is redundant.

Tom Lavedas
===========

>-----Original Message-----
>That is what I am getting in file:
>?????&#12320;&#12848;&#12855;&#12592;&#12595;&#27714;&#25973;&#29251;&#2955
1;&#8307;&#27714;&#25973;&#26707;&#25961;&#25708;????????????????????&#22616
;&#13648;&#13618;&#12595;&#12600;
&#14649;
>&#12576;&#8241;??&#30032;&#28276;&#28001;????????&#12832;&#12336;&#12339;&#
12856;`?????&#24919;&#30313;&#25701;?&#8270;&#19488;&#21833;?????????????&#1
8976;
>.
>