Author Topic: storing to bin file  (Read 9182 times)

tools-n-stuff

  • Newbie
  • *
  • Posts: 38
storing to bin file
« on: October 28, 2010, 10:09:27 AM »
Using the Book HN, i am trying to store the data created by the user to a bin file. The reason i am looking at using a bin file is because i read that writing to a file (excel i imagine) is a little limited by the number of entries.
So my first question is:
Is bin the way to go?

I have looked at the example contained within the Hn built in guide and pasted the example into my project.

GUIDE example - as is.
Code: [Select]
These show how to write and read to/from binary files. No checking for the files existence or type is made using fdets.

Note if the file variable fvar is zero then the file does not exist.

@ Write to a named file
Local fname,fvar,fdets,ftypes,fpaths,fnames,fextens
Local findex,n
FileGet(fname,fvar,fdets,ftypes,fpaths,fnames,fextens)
CreateBFile(fvar,findex,n)
WriteBVariable(findex,'hello')
For n=1 to 10
    WriteBByte(findex,n)
EndFor
CloseBFile(findex)

@ Read from a named file, assumes format known
Local fname,fvar,fdets,ftypes,fpaths,fnames,fextens
Local findex,n
FileGet(fname,fvar,fdets,ftypes,fpaths,fnames,fextens)
OpenAsBFile(fvar,findex)
ReadBVariable(findex,mess)
For n=1 to 10
    ReadBByte(findex,num)
    Put num After mess
EndFor
CloseBFile(findex)
 
The read part i have tried placing it on the home card and on card 2 which is the main working environment. And the 'write' part i have tried placing on an independant button and directly on the Book HNs update button. I remember last night that on one try i got a conflict on 'nVar' as been already used!!?? I could see being used twice but couldn't work out if i should or how to get them to work together.

From what i can gather from this example, it should create a bin file in the data store, but i can't see it.

Any chance of a few pointers as to how to create a bin file as i am lost again. I can't work out if someting else should be declared and where, or if its needed to get the bin file hooked up to the project.

One thing i thought of thought:
When writing to a bin or file will it save all the fields from that Book HN page entry or does something need to be done so that the bin file knows there are more than one field, and doe's it know that there are more than one page with reusing the same fields but with new data? I know it maybe a lame question, but i am just trying to understand what i am doing.

Thanks in advance.
« Last Edit: January 01, 1970, 01:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 464
  • Here to help you
Re: storing to bin file
« Reply #1 on: October 28, 2010, 09:26:34 PM »
Quote
The read part i have tried placing it on the home card and on card 2 which is the main working environment. And the 'write' part i have tried placing on an independant button and directly on the Book HNs update button. I remember last night that on one try i got a conflict on 'nVar' as been already used!!?? I could see being used twice but couldn't work out if i should or how to get them to work together.

From what i can gather from this example, it should create a bin file in the data store, but i can't see it.

Any chance of a few pointers as to how to create a bin file as i am lost again. I can't work out if someting else should be declared and where, or if its needed to get the bin file hooked up to the project.

You were nearly there - the reason that nVar is flagged as an error - 'already in use' - is because it is declared twice as a local variable within the same script. Only one variable can have that name withing a script otherwise the compiler would get confused.

This post shows how to save some data as a binary Excel file:-

  http://www.tigabyte.com/forums/viewtopic.php?f=22&t=14


Quote
One thing i thought of thought:
When writing to a bin or file will it save all the fields from that Book HN page entry or does something need to be done so that the bin file knows there are more than one field, and doe's it know that there are more than one page with reusing the same fields but with new data? I know it maybe a lame question, but i am just trying to understand what i am doing

Use variables to save data into your bin files.
Its probably best to make 2 global procedures - they go into MainCode section
The first procedure saves and the second loads. Pass the data to both procedures using global variables and ensure that they are in the same order within both the save and load procedure.

It is also possible to read any field even though it is not on the current card or is read from the MainCode section:-

Code: [Select]
Local x

@ get field 7 on card 21
Put FieldCardFN(21,7) into x

WriteBVariable(findex,x)

Actually it might be better just to load global variables as they are much simpler.
« Last Edit: August 03, 2011, 06:59:52 AM by tigabyte »
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

 

anything