[Gambas-user] Write to file is adding strange characters

nando nando_f at ...951...
Wed Dec 26 21:42:26 CET 2007


When you use the WRITE statement, there are two ways to use it:
1)  WRITE #hFile, test
2)  WRITE #hFile, test, LEN(test)

Explanation...

1) Gambas adds the length of the string as part of the written data.
   This one will cause you problems because it adds lenght automatically.
2) Gambas adds nothing and writes only the quantity of bytes 
   specified by LEN(test) WITHOUT adding anything else to the file.

Use 2) by adding   ,LEN(string var) and the file will be as you expect.

-Fernando


---------- Original Message -----------
From: Benoit Minisini <gambas at ...1...>
To: mailing list for gambas users <gambas-user at lists.sourceforge.net>
Sent: Wed, 26 Dec 2007 20:32:28 +0100
Subject: Re: [Gambas-user] Write to file is adding strange characters

> On mardi 25 décembre 2007, lawrence pires wrote:
> > Im trying to automate the writing of a dvd.xml file.
> >
> > Im trying to create and write the following text into a file:
> >
> >  <dvdauthor>  <vmgm />    <titleset>      <titles>        <pgc>
> >   <vob file="your_video.mpg" chapters="0,0:20,0:30,0:40,0:50,0:60" />
> >       </pgc>      </titles>    </titleset></dvdauthor>
> >
> >
> > Heres the code im using:
> >
> > PUBLIC SUB Button2_Click()
> > DIM hFile AS File
> > DIM test AS String
> > DIM test1 AS String
> > DIM test3 AS String
> >
> > test = "<dvdauthor> \n<vmgm /> \n<titleset>\n<titles>\n<pgc>\n"
> > test1 = "<vob" "file=\"your_video.mpg\""
> > "chapters=\"0,0:20,0:30,0:40,0:50,0:60\"" "/>"
> > test3 = "\n</pgc>\n</titles>\n</titleset>\n</dvdauthor>"
> >
> > hFile = OPEN "/home/don/Desktop/dvd" FOR CREATE
> >
> > WRITE #hFile, test
> > WRITE #hFile, test1
> > WRITE #hFile, test3
> > FLUSH #hFile
> > CLOSE #hFile
> > END
> >
> > And this is the contents after the above has been executed:
> >
> > 1<dvdauthor>
> > <vmgm />
> > <titleset>
> > <titles>
> > <pgc>
> > @<vobfile="your_video.mpg"chapters="0,0:20,0:30,0:40,0:50,0:60"/>*
> > </pgc>
> > </titles>
> > </titleset>
> > </dvdauthor>
> >
> >
> > As you can see is writing strange characters to the dvd.xml file.
> >
> >
> > can anyone please help me?
> >
> > Kind regards & Happy Christmas
> 
> WRITE is for writing binary data. Use PRINT to write text data.
> 
> Regards,
> 
> -- 
> Benoit Minisini
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------





More information about the User mailing list