Revision history for KeyPgRandom


Revision [22548]

Last edited on 2019-01-12 09:23:39 by CountingPine [binary -> random access]
Additions:
Specifies file or device to be opened for random access mode
Deletions:
Specifies file or device to be opened for binary mode


Revision [22236]

Edited on 2018-02-11 11:53:24 by JeffMarshall [fix link]
Additions:
- Care must be taken with dynamic or fixed length strings inside user defined types (UDT), see the warning at [[KeyPgType|Type]].
Deletions:
- Care must be taken with dynamic or fixed length strings inside user defined types (UDT), see the warning at KeyPgType.


Revision [21646]

Edited on 2016-10-30 18:57:36 by fxm [Formatting]
Additions:


Revision [21102]

Edited on 2016-03-13 09:38:22 by fxm [Formatting]

No Differences

Revision [20476]

Edited on 2016-02-10 16:07:27 by DkLwikki [Update link format]
Additions:
[[KeyPgOpen|Open]] //filename// for **Random** [[[KeyPgAccess|Access]] //access_type//] [[[KeyPgLock|Lock]] //lock_type//] as [#]//filenum// [Len = //record_length//]
If the file does not exist, a new file will be created, otherwise any data existing in the file is preserved by ##[[KeyPgOpen|Open]]##. The file pointer is initialized by ##[[KeyPgOpen|Open]]## at the start of the file, at record number ##1##. File operations move the file position in steps of ##//record_length//## bytes.
This file mode uses an user-defined ##[[KeyPgType|Type]]## buffer variable to read/write full records in a file. The buffer variable uses to include several fields.
The data is saved in binary mode, in the same internal format ""FreeBASIC"" uses, by means of ##[[KeyPgGetfileio|Get #]]## and ##[[KeyPgPutfileio|Put #]]##.
##//Access_type//## - By default ##**Random**## mode allows to both read and write the file, unless an ##[[KeyPgAccess|Access]]## type is specified, it must be one of:
##[[KeyPgLock|Lock]]## and ##[[KeyPgUnlock|Unlock]]## can be used to restrict temporally access to parts of a file.
##//filenum//## is a valid ""FreeBASIC"" file number (in the range ##1..255##) not being used for any other file presently open. This number identifies the file for the rest of file operations. A free file number can be found using the ##[[KeyPgFreefile|FreeFile]]## function.
##//record_length//## is the amount of bytes the file pointer will move for each individual ##[[KeyPgGetfileio|Get]]## and ##[[KeyPgPutfileio|Put]]##, it must match the size of the buffer variable used when ##[[KeyPgGetfileio|Get]]##ting and ##[[KeyPgPutfileio|Put]]##ting data. If omitted, it defaults to ##128##.
- The keyword ##[[KeyPgField|Field]]## can only be used with ##[[KeyPgType|Type]]## to specify the packing of the UDT.
- ##[[KeyPgOpen|Open]]##
- ##[[KeyPgBinary|Binary]]##
- ##[[KeyPgGetfileio|Get #]]##
- ##[[KeyPgPutfileio|Put #]]##
Deletions:
[[KeyPgOpen Open]] //filename// for **Random** [[[KeyPgAccess Access]] //access_type//] [[[KeyPgLock Lock]] //lock_type//] as [#]//filenum// [Len = //record_length//]
If the file does not exist, a new file will be created, otherwise any data existing in the file is preserved by ##[[KeyPgOpen Open]]##. The file pointer is initialized by ##[[KeyPgOpen Open]]## at the start of the file, at record number ##1##. File operations move the file position in steps of ##//record_length//## bytes.
This file mode uses an user-defined ##[[KeyPgType Type]]## buffer variable to read/write full records in a file. The buffer variable uses to include several fields.
The data is saved in binary mode, in the same internal format ""FreeBASIC"" uses, by means of ##[[KeyPgGetfileio Get #]]## and ##[[KeyPgPutfileio Put #]]##.
##//Access_type//## - By default ##**Random**## mode allows to both read and write the file, unless an ##[[KeyPgAccess Access]]## type is specified, it must be one of:
##[[KeyPgLock Lock]]## and ##[[KeyPgUnlock Unlock]]## can be used to restrict temporally access to parts of a file.
##//filenum//## is a valid ""FreeBASIC"" file number (in the range ##1..255##) not being used for any other file presently open. This number identifies the file for the rest of file operations. A free file number can be found using the ##[[KeyPgFreefile FreeFile]]## function.
##//record_length//## is the amount of bytes the file pointer will move for each individual ##[[KeyPgGetfileio Get]]## and ##[[KeyPgPutfileio Put]]##, it must match the size of the buffer variable used when ##[[KeyPgGetfileio Get]]##ting and ##[[KeyPgPutfileio Put]]##ting data. If omitted, it defaults to ##128##.
- The keyword ##[[KeyPgField Field]]## can only be used with ##[[KeyPgType Type]]## to specify the packing of the UDT.
- ##[[KeyPgOpen Open]]##
- ##[[KeyPgBinary Binary]]##
- ##[[KeyPgGetfileio Get #]]##
- ##[[KeyPgPutfileio Put #]]##


Revision [15319]

Edited on 2011-10-01 11:36:45 by DkLwikki [Fixme: Reword weird sentence, correct or not?]
Additions:
- Care must be taken with dynamic or fixed length strings inside user defined types (UDT), see the warning at KeyPgType.
Deletions:
- In QB, String-contained runtime user defined types (UDT) are not implemented in ""FreeBASIC"".


Revision [15318]

Edited on 2011-10-01 11:31:12 by DkLwikki [Update example, add second one]
Additions:
{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/math/random1.bas"}}%%(freebasic)
'' This example generates a test file and then lets you view random records
'' that are read live from the file.
type Entry
dim u as Entry
open "testfile" for random as #1 len = sizeof(Entry)
'' Write out 9 records with predefined data
for i as integer = 1 to 9
put #1, i, u
'' Let the user view records by specifying their index number
dim i as integer
close #1
{{fbdoc item="filename" value="examples/manual/math/random2.bas"}}%%(freebasic)
type ScoreEntry field = 1
as string * 20 name
as single score
dim as ScoreEntry entry
'' Generate a fake boring highscore file
open "scores.dat" for random access write as #1 len = sizeof(entry)
for i as integer = 1 to 10
entry.name = "Player " & i
entry.score = i
put #1, i, entry
close #1
'' Read out and display the entries
open "scores.dat" for random access read as #1 len = sizeof(entry)
for i as integer = 1 to 10
get #1, i, entry
print i & ":", entry.name, str(entry.score), entry.score
close #1
Deletions:
{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/math/random.bas"}}%%(freebasic)
type UDT
dim i as integer
dim u as UDT
dim ff as ubyte
dim fpos as integer
ff = freefile
fpos = 10
open "testfile" for random as #ff len=sizeof(UDT)
for i = 1 to 9
put #ff, i, u
close #ff
end 0


Revision [13845]

Edited on 2008-10-30 19:20:06 by CountingPine [Update example, add second one]
Additions:
##//filenum//## is a valid ""FreeBASIC"" file number (in the range ##1..255##) not being used for any other file presently open. This number identifies the file for the rest of file operations. A free file number can be found using the ##[[KeyPgFreefile FreeFile]]## function.
- The keyword ##[[KeyPgField Field]]## can only be used with ##[[KeyPgType Type]]## to specify the packing of the UDT.
Deletions:
##//filenum//## is a valid ""FreeBASIC"" file number (in the range ##1##-##255##) not being used for any other file presently open. This number identifies the file for the rest of file operations. A free file number can be found using the ##[[KeyPgFreefile FreeFile]]## function.
- The keyword ##[[KeyPgField Field]]## is used with ##[[KeyPgType Type]]## to specify the packing of the UDT.


Revision [13467]

The oldest known version of this page was created on 2008-07-03 10:39:26 by CountingPine [Update example, add second one]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode