GLBasic forum

Main forum => FAQ => Topic started by: Hemlos on 2008-Oct-21

Title: The Nature of WRITE
Post by: Hemlos on 2008-Oct-21
When i use openfile(#,$,false#)  is this creating a text file? or a binary?
Title: Re: The Nature of WRITE
Post by: D2O on 2008-Oct-21
I think this it always Binary is.

A text editor then interprets only the content legibly to one writes.
Title: Re: The Nature of WRITE
Post by: Moru on 2008-Oct-21
A file is just a file. It's what program it is designed to be used with that decides if it's binary or ascii. If you only write readable characters and CR/LF, TAB and similar things it becomes a textfile, if you write random data to it, it's binary. You can even have half of it be a textfile and the other half to be binary.

What are you having problems with?
Title: Re: The Nature of WRITE
Post by: Hemlos on 2008-Oct-22
Indeed, WRITE creates binaries. 
I created a program, to build my first binary today, GLMidi.mid
I only needed to use WRITEBYTE, with ASC() for some charaters. And hex, i used the asc2hex$%(#0-255) converter which i added in the codesnipets forum.
Title: Re: The Nature of WRITE
Post by: Schranz0r on 2008-Oct-22
Hemlos:

Code?!

:whistle:
Title: Re: The Nature of WRITE
Post by: Hemlos on 2008-Oct-22
You want me to reveal my industrial secrets and i havent even gotten past one note of music lol :P
Title: Re: The Nature of WRITE
Post by: Schranz0r on 2008-Oct-25
hehehe ;)
Title: Re: The Nature of WRITE
Post by: Kosta on 2008-Oct-31
i have the problem, that files with openfile are binarys.....

how can i create a CR/LF in a file (file is opened with OPENFILE (trying to write something on it))

i have tried both posibilities

   WRITESTR 2,"\n"
   WRITESTR 2,CHR$(13)

but my file is still a one-liner (with the []* sign as CR/LF)


*= the CR/LF of Unixfiles seen on DOS
Title: Re: The Nature of WRITE
Post by: Moru on 2008-Oct-31
I usualy use WRITELINE 1, a$ to write textfiles.
Title: Re: The Nature of WRITE
Post by: Hemlos on 2008-Oct-31
Indeed, I recommend writeline as well.

When writing, WRITELINE will put an "\r\n" at the end of the line.
If you want to write UNIX format CR's, use: WRITESTR 1, text$ + "\n"
And dont forget to CLOSEFILE 1

Putfile is a pain, you have to write all the line numbers, makes it difficult to edit a help file or game instructions.

Getfile is ok for grabbing a line, because you can select the line number...good for scripts, just make sure you clear the getfile buffer after use: getfile "",null$


Title: Re: The Nature of WRITE
Post by: Moru on 2008-Oct-31
Not to mention that GETFILE / PUTFILE only supports 256 lines wich only makes it useful for very small files. Those few times I have use for it I'm parsing files with 10 000 or 100 000 lines.
Title: Re: The Nature of WRITE
Post by: Kitty Hello on 2008-Nov-03
use OPENFILE and such. GETFILE is only fr compatibility reasons there.