September 20, 2020, 06:14:26 am


Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........

Save As Binary

Started by aurelCB, August 05, 2009, 03:35:39 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


Hi all...
I made one small example of how save file as binary.
I just modify little bit one piece of code from Asteroids example.

Code Select
' Save As Binary file...test
DEF win:window
def hs:BFILE
def topten[4]:char
def score:int

Window win,0,0,400,300,@minbox,0,"Save As Binary",main

'create a blank one if it doesn't exist
IF(openfile(hs,GETSTARTPATH + "Aurel.test1","R") = 0)
for x = 1 to 4
GET hs,x,topten[x-1]
next x
closefile hs
if(openfile(hs,GETSTARTPATH + "Aurel.test1","W") = 0)
topten[0] = &H50
topten[1] = &H45
topten[2] = &H0
topten[3] = &H0
for x = 1 to 4
PUT hs,x,topten[x-1]
next x
closefile hs
'IF topten[3] = &H0 then Messagebox 0,"File updated","OK!",64
IF topten[3] = &H0 then Messagebox 0,"File updated","OK!",64

waituntil win=0

Sub main
select @class
case @idclosewindow
closewindow win

Then i search for new file in Creative samples folder and found them with name Aurel.test1.
So this is OK file is saved, then i open this file with Notepad just for see what is in there.
And found something weird it says  PE E.
Hmm what is That?
forum for hobby programming:<br />


Hi Aurel,

Binary files write incomprehensible stuff to the file.  The only way to recover data from a binary file is to read it back the same way as you wrote it.

In this case using the corresponding GET statements.

&H50, &H45  are integer 80 and 69 - and these are characters P and E in the ASCII table.

Nothing wrong, it's just that the binary format screws up your data values ..  :)

all the best,

Tomorrow may be too late ..


Hi mr.Graham... :)

Stupid me... ::)
I forget to tell from where i use this values (bytes).
This values is from small VB written PE header and is obvius present PE exe header
written in binary.I just mess somethings like usual ::) ::)
But exactly work as espected .
This code is start when linker made PE executable and i supose that is part of any
windows PE exe file( i think...).
I will make more tests becose i find the rest of code.
So not bad , Cbasic program can make exe with code .... cool isn't  ;D ;D ;D

all best...
forum for hobby programming:<br />