Re: Format file writing by McKirahan
McKirahan
Sat May 03 07:15:54 CDT 2008
"McKirahan" <News@McKirahan.com> wrote in message
news:4eWdnRTD3fdMy4HVnZ2dnUVZ_r6rnZ2d@comcast.com...
> "seb" <seb@hotmail.com> wrote in message
> news:481c38f8$0$736$426a74cc@news.free.fr...
> > Hi,
> >
> > I would like to write in test file "01","02", ....,"99"
> > For this I wrote,
> >
> > Dim MyFile
> > Const ForWriting = 2
> >
> > Set objFichier = CreateObject("Scripting.FileSystemObject")
> > Set MyFile = objFichier.OpenTextFile("test.txt",ForWriting,True)
> >
> > for i = 1 to 99
> > m=""""+CStr(i)+""""+","
> > MyFile.Writeline m
> > next
> >
> > MyFile.Close
> > Wscript.Quit 0
> >
> > This doesn't work, as test.txt has,
> >
> > 1,
> > 2,
> > 3,
> > ...
> > 99,
> >
> > 1) How avoid to go to next line after each Myfile.Writeline ?
> > 2) How to format 1 to 01 ?
>
> Will this help?
>
> Option Explicit
> '*'
> Dim i, s
> For i = 1 To 99
> s = s & Chr(34) & Right(CStr(100+1),2) & Chr(34) & ","
> Next
> s = Left(s,Len(s)-1)
> '*'
> Dim objFichier
> Set objFichier = CreateObject("Scripting.FileSystemObject")
> Dim MyFile
> Set MyFile = objFichier.CreateTextFile("test.txt",True)
> MyFile.Write s
> MyFile.Close
> '*'
> Wscript.Quit 0
Typo! Use this line instead:
s = s & Chr(34) & Right(CStr(100+i),2) & Chr(34) & ","