Qbasicnews.com

Full Version: Random File/Packed length
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to make a random file but I'm not sure how to figure the length and packed length of each data.
Packed length?

dim record as recordtype

Recordnum=lof(1)\len(record)
I don't understand that. What I mean is that when I open a random file I have to specify how large it is, depending on the data. How do I figure the packed length and length of each data.
I have just answered your question. That is, assuming I understand it. ;*)

Okay let's says you have a random file that you already have opened...


You certainly would want to use types here.

Say you have a type:

Code:
type recordtype
      Nam     as string * 50
      age      as integer
      sex       as string *1
end type

now you want to dimension a record as that type...

Code:
Dim record as recordtype

Lof(1) gets the length of file in bytes so you have to get the length of the record to get the number of records...

Code:
Numrec=Lof(1)\Len(record)


so LOF(1) returns the (L)ength (O)f (F)ile.

;*)
The only way I know how to create a random file is by this:


Code:
FILEOPEN:
     OPEN "R", #1 "cust.dat", 128
     FIELD #1, 4 AS custnum$, 30 AS custname$, 30 AS custaddr1$, 20 AS custcity$. 2 AS custcity, 2 AS custst$, 4 AS custst$, 4 AS custzip$, 2 AS custtype$, 8 AS custbal$
     RETURN

An example but I don't know how they figured out the length of each data.
Geez, that don't even look like QBasic!

I suggest you read the QBasic help more thoroughly (try clicking on the "QBOHO" link above, because it looks suspiciously like you're barking up the wrong tree Wink
DValan: That's the old way of doing random access files. Types simplifies things. ;*)
Hmm it's copied right out of my Qbasic teach yourself book. It was written like 10 years ago though. Smile