The Nature of WRITE

Previous topic - Next topic

Hemlos

When i use openfile(#,$,false#)  is this creating a text file? or a binary?
Bing ChatGpt is pretty smart :O

D2O

I think this it always Binary is.

A text editor then interprets only the content legibly to one writes.
I7 2600K; 8 GB RAM ; Win10 Pro x64 | NVidia GTX 750 TI 2048MB ; Realtec OnBoard Sound;
Lenovo ThinkPad T400: XP Pro
GLB Premium-immer Aktuell

Moru

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?

Hemlos

#3
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.
Bing ChatGpt is pretty smart :O

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Hemlos

You want me to reveal my industrial secrets and i havent even gotten past one note of music lol :P
Bing ChatGpt is pretty smart :O

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kosta

#7
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
Intel QuadCore, Geforce8600GT,512MB,4GB Ram, 26" TFT
HP nw8440 Schläppy
GP2X Mk2 (Firmware 3.0)

GLBASIC Blog:
http://www.glbasic.com/forum/index.php?blog=51.0

Moru

I usualy use WRITELINE 1, a$ to write textfiles.

Hemlos

#9
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$


Bing ChatGpt is pretty smart :O

Moru

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.

Kitty Hello

use OPENFILE and such. GETFILE is only fr compatibility reasons there.