Before You Post, Please Note...

-> Please Note: By Posting, you agree to submit the contents of your post to the Public Domain <- SEE: howto post to this blog

Friday, February 2, 2007

puppybasic intro ch. 09 - working with binary files

green text is being edited and should not be considered  
relevant to the tutorial.
for a while, it will make up
the bulk of this section.

black text has been edited to be more accurate with
regards to puppybasic.

........................................................................
working with binary files
1 of 7




an intro to puppybasic

chapter 9: working with binary files







........................................................................

........................................................................
working with binary files
2 of 7

it might be fun at this point to learn how to save and load some data in
a file, but this will be much more useful when you've learned about
decision making and loops. in the meantime, here is how to work with
binary files:

first of all, be sure to use this statement at the beginning of your
program:
DIM bt AS STRING * 1

so that you have a one byte string to work with. you can make longer
strings, but this one will work for any purpose.


........................................................................

........................................................................
working with binary files
3 of 7

always open the file :)

OPEN "filename.txt" FOR BINARY AS #1

if you are only going to read the file, you dont strictly need the bt
variable, and therefore don't need to DIM at the start of your program.
just INPUT a byte:

b$=INPUT$(1, #1)

and that's all there is to that. yes, it IS similar to keyboard input.


........................................................................

........................................................................
working with binary files
4 of 7

do it again to read the next byte. usually, you'll probably want to use
this method instead:

GET #1, q, bt
with q being the byte of the file you want to read... if q is 57, then
it will read the 57th byte of the file.

to write, use:
PUT #1, q, bt
where b is a string that's only one byte (or letter) long. it's pretty
much the same idea. some useful functions for working with files are:


........................................................................

........................................................................
working with binary files
5 of 7

q = FREEFILE

sets q to the number of the next filenumber that's free... if you've
opened a file as #1, and a second file, as #2, then FREEFILE will equal
3.

LOC(n)

is the byte you're set to read or write at. if you've used INPUT$(1, #1)

50 times already, LOC(1) will be 51.


........................................................................

........................................................................
working with binary files
6 of 7

LOF(n)

is worth remembering, LOF(n) is equal to the length of file #n, if you
open a file as #1 and the LOF(1) is 0, that file is empty.

always close the file when you're done working with it:

CLOSE #1

if you are only working with one file, or if you don't have any other
files that you need to leave open, using close with no file numbers:


........................................................................

........................................................................
working with binary files
7 of 7

CLOSE

will close all files.


-= end of chapter 9 =-







........................................................................
an intro to puppybasic (chapter 9)
this content is public domain.
........................................................................


click here to go back to the contents page

26 comments:

Anonymous said...

buy tramadol online buy tramadol cod shipping - tramadol hcl related substances

Anonymous said...

xanax online alprazolam 0.5mg tab purepac - 0.5 mg xanax effects

Anonymous said...

tramadol generic where can i buy tramadol usa - tramadol medication no prescription

Anonymous said...

generic xanax xanax length of effect - xanax high how much

Anonymous said...

buy tramadol online safe buy tramadol online - can tramadol for dogs get you high

Anonymous said...

buy tramadol online tramadol 50 mg over counter - order cheap tramadol online

Anonymous said...

buy carisoprodol soma carisoprodol wiki - carisoprodol soma indications

Anonymous said...

buy cheap carisoprodol carisoprodol dose erowid - carisoprodol opiate withdrawal

Anonymous said...

buy tramadol online tramadol 50 mg kaps ratiopharm - will 100mg tramadol do

Anonymous said...

buy cialis online generic cialis ervaringen - buy cialis online fast

Anonymous said...

tramadol no prescription buy generic tramadol no prescription - tramadol for dogs with liver disease

Anonymous said...

buy tramadol online no prescription tramadol vicodin high - buy tramadol cod overnight delivery

Anonymous said...

cialis pills best place buy cialis online us - cialis from us online pharmacy

Anonymous said...

cialis no rx generic cialis release date - cialis online andorra

Anonymous said...

buy cialis 10mg buy cialis kl - generic cialis viagra online

Anonymous said...

http://blog.dawn.com/dblog/buy/#85714 tramadol 60 mg - tramadol 50 mg and pregnancy

Anonymous said...

http://landvoicelearning.com/#57594 order tramadol online check - tramadol addiction symptoms

Anonymous said...

http://landvoicelearning.com/#23561 buy tramadol online forum - tramadol 800 mg day

Anonymous said...

best buy tramadol buy tramadol overnight delivery - buy tramadol online safe

Anonymous said...

buy tramadol online cod overnight tramadol recreational high - tramadol hydrochloride 100 mg side effects

Anonymous said...

http://reidmoody.com/#36921 ativan xanax together - ativan drug interactions

Anonymous said...

learn how to buy tramdadol buy tramadol online florida - does tramadol hcl 50 mg get you high

Anonymous said...

ativan price ativan for drug addiction - ativan gel side effects

Anonymous said...

http://staam.org/#56274 tramadol 100mg used - order tramadol online to florida

Anonymous said...

http://staam.org/#92453 tramadol for dogs dosage - buy tramadol online with mastercard

Anonymous said...

http://bayshorechryslerjeep.com/#8193 xanax withdrawal constipation - xanax overdose how many