[Gambas-user] Mystery characters added to start of html file

Benoit Minisini gambas at ...1...
Sun Jan 27 14:01:59 CET 2008


On samedi 26 janvier 2008, richard terry wrote:
> I'm writing my drug browser which consists of a 50MB postgres backend of
> data and a simple gui to search/manipulate/display the data (see the screen
> dump). I've written something similar in basic 11 years ago, and a couple
> of years ago in wxPython, so its only taken a couple of hours to knock up,
> though I'm still struggling with the gambas syntax (shouldn't be as it is
> quite simple!!!)
>
> The drug product information retreived after quite complex multi-join
> queries is quite simple - fields such as $Result!composition,
> $Result!indications etc, and I've chosen to do a string substitute of the
> fields for a corresponding name in a hmtl template like this:
>
> <h2> <FONT COLOR="#000070"><a name=Composition></a>Composition</FONT></h2>
> %(composition)s<br>
>
> (in my python version this %(composition)s structure meant I could
> substitute a whole dicitonary into the template in one call, don't know if
> that is possible in gambas basic so I've just done a section by section
> substitution.
>
> Anyhow, I hence end up with the html document as per the picture which is
> actually in a textedit control
>
> If I save it from the internal string generated (not from the textedit)
> using this code:
>
>   DIM hfile AS File
>   DIM sFilename AS String
>    sFilename = "/home/richard/tmp/temp.html"
>    hfile = OPEN sFilename FOR WRITE CREATE
>    WRITE #hfile, st      'st is the html string I've created
>    CLOSE #hfile
>
> I end up with a couple of extra bytes at the start of the file which then
> are displayed at the top if I re-display the  file.
>
> ��<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
> Transitional//EN"><html><head> <meta content="text/html;
>
> I've checked by printing out at the console prior to the write, and they
> don't show up as being in the string.
>
> Thanks in advance, any help appreciated.
>
> Richard

You must use PRINT, not WRITE, which write data in a binary form. In your 
specific case, the strange characters are the length of the string written 
before the string contents.

Read the documentation on the wiki about the WRITE instruction for more 
information.

Regards,

-- 
Benoit Minisini




More information about the User mailing list