'Type' and random files
#1
Hi, .. I have created a Type called DS01.

In regards to random files, how do I use DS01 with Field, Put and Get statements ?

Regards,

Mike
Reply
#2
http://www.qb64.net/wiki/index.php/GET (see first example)

Need to use fixed length strings for strings in a Record Type declaration.

(Although Pete did mention something about variable length records at QB64.net as I recall.)
B += x
Reply
#3
Hi bplus, thank you for your help. I dd see the example but I was wondering about the use of Filed, Lset, Rset etc..
There is no mention of these statements in the example .. or other examples I have seen.
Mike
Reply
#4
Man! I haven't used these terms for years, since I was making custom database files at work early 90's.

Lset and Rset have to do with mounting text into a fixed string:
http://www.qb64.net/wiki/index.php?title...ext=Search

I've never seen Filed before, are you sure it's a keyword? and not a variable, say a Boolean for setting true / false if file is filed?
B += x
Reply
#5
@bplus: I think he misspelled Field.
dndbbs project:

Links to my MUD: (strictly 16-bit); AKA XP:

Dndbbs executables
http://www.filegate.net/pdn/pdnbasic/dnd50a1e.zip

Dndbbs source
http://www.filegate.net/pdn/pdnbasic/dnd50a1s.zip

Dndbbs upgrade
http://www.filegate.net/pdn/pdnbasic/dnd50a1u.zip

DNDDOOR - https://bit.ly/EriksDNDDoor DUNGEON - https://bit.ly/EriksDungeon
Interpreter - https://bit.ly/EriksSICK Hex Editor - https://bit.ly/EriksHexEditor Utilities - https://bit.ly/EriksUtils
QB45 files: - https://bit.ly/EriksQB45 QB64shell - https://bit.ly/QB64shell Some old QB64 versions: - https://bit.ly/OldQB64
Reply
#6
Thanks Erik, I think you're correct just moved the e over...

There is a Keyword Field (which I want to spell Feild) :
http://www.qb64.net/wiki/index.php/FIELD

I have not seen nor do I recall ever seeing this Field method used. I am thinking I had always used Get and Put record numbers with records defined with a Type declaration. I like the symmetry. So even now that I know a Field option does exist, I would go with a Type defined record. Unless someone points out the advantage of the field method. (And there probably is one, if there are two methods to do this kind of thing.)

EDIT: my English is terrible specially first thing in the morning. :/
B += x
Reply
#7
Field can be very useful when using random records:

Code:
' sample using random records
TYPE RecType
    var1 AS INTEGER
    var2 AS DOUBLE
END TYPE
DIM Record AS RecType
' open file and declare record
Filename$ = "tempfile.dat"
OPEN Filename$ FOR RANDOM AS #1 LEN = LEN(Record)
FIELD 1, 2 AS v1$, 8 AS v2$
' write ten random records
FOR L = 1 TO 10
    Record.var1 = L
    Record.var2 = L
    PUT 1, L, Record
NEXT
' use MKI$/CVI for integers
FOR L = 1 TO 10
    GET 1, L
    PRINT CVI(v1$);
NEXT
dndbbs project:

Links to my MUD: (strictly 16-bit); AKA XP:

Dndbbs executables
http://www.filegate.net/pdn/pdnbasic/dnd50a1e.zip

Dndbbs source
http://www.filegate.net/pdn/pdnbasic/dnd50a1s.zip

Dndbbs upgrade
http://www.filegate.net/pdn/pdnbasic/dnd50a1u.zip

DNDDOOR - https://bit.ly/EriksDNDDoor DUNGEON - https://bit.ly/EriksDungeon
Interpreter - https://bit.ly/EriksSICK Hex Editor - https://bit.ly/EriksHexEditor Utilities - https://bit.ly/EriksUtils
QB45 files: - https://bit.ly/EriksQB45 QB64shell - https://bit.ly/QB64shell Some old QB64 versions: - https://bit.ly/OldQB64
Reply
#8
Since Field has been around long before Type here is another sample:

Code:
' open file and declare record
Filename$ = "tempfile.dat"
OPEN Filename$ FOR RANDOM AS #1 LEN = 14
FIELD 1, 2 AS v1$, 4 AS v2$, 8 AS v3$
' write ten records
FOR L = 1 TO 10
    LSET v1$ = MKI$(L): LSET v2$ = MKS$(L): LSET v3$ = MKD$(L)
    PUT 1, L
NEXT
' read records
FOR L = 1 TO 10
    GET 1, L
    PRINT CVI(v1$); CVS(v2$); CVD(v3$)
NEXT
dndbbs project:

Links to my MUD: (strictly 16-bit); AKA XP:

Dndbbs executables
http://www.filegate.net/pdn/pdnbasic/dnd50a1e.zip

Dndbbs source
http://www.filegate.net/pdn/pdnbasic/dnd50a1s.zip

Dndbbs upgrade
http://www.filegate.net/pdn/pdnbasic/dnd50a1u.zip

DNDDOOR - https://bit.ly/EriksDNDDoor DUNGEON - https://bit.ly/EriksDungeon
Interpreter - https://bit.ly/EriksSICK Hex Editor - https://bit.ly/EriksHexEditor Utilities - https://bit.ly/EriksUtils
QB45 files: - https://bit.ly/EriksQB45 QB64shell - https://bit.ly/QB64shell Some old QB64 versions: - https://bit.ly/OldQB64
Reply
#9
"Unless someone points out an advantage to Field Method."

Hi Erik,

Being unfamiliar with Field method, your code is hard to translate and read with understanding let alone see any advantage to using it.

Can you say what advantage is without writing code?

Then I might be able to understand your examples and more importantly know when to use Field method and when to use Type. So far, I am seeing Field applied only to strings and conversions required to get numerical data back to numeric form. I know it would be better, faster and more efficient for numerical data to use Type if all those CV's are needed.

So I assume, if there be an advantage to using Field method it would be with records that are all string data or mostly. A 100 variable length strings can fit in a smaller fixed string space or record length than making space for maximum string size for each data item but then you loose space for a character separating data items. (And Field seems applied to fixed length strings anyway!)

I am suspecting Field was the primitive way before the invention and use of Type. Specially as you say, it existed before Type.
Quote:Since Field has been around long before Type here is another sample

In that case, I surmise:
The only advantage to using Field method is because you have code already written using that method, ie for compatibility to old code.  Correct? or am I missing another advantage?

Also Type has been around since at least early to mid 90's either Quick Basic or VB for DOS had it, so code using Field Method must be really ancient. (GW BASIC???)
B += x
Reply
#10
Did I say there was any advantage in using Field over Type? No.

Is there any advantage in using Field over Type? No.

I merely entered the code because MLambert asked.

And I have tried to make the code as readable as possible.

Thanks, Erik.

btw:
Quote:so code using Field Method must be really ancient. (GW BASIC???)

it is...
dndbbs project:

Links to my MUD: (strictly 16-bit); AKA XP:

Dndbbs executables
http://www.filegate.net/pdn/pdnbasic/dnd50a1e.zip

Dndbbs source
http://www.filegate.net/pdn/pdnbasic/dnd50a1s.zip

Dndbbs upgrade
http://www.filegate.net/pdn/pdnbasic/dnd50a1u.zip

DNDDOOR - https://bit.ly/EriksDNDDoor DUNGEON - https://bit.ly/EriksDungeon
Interpreter - https://bit.ly/EriksSICK Hex Editor - https://bit.ly/EriksHexEditor Utilities - https://bit.ly/EriksUtils
QB45 files: - https://bit.ly/EriksQB45 QB64shell - https://bit.ly/QB64shell Some old QB64 versions: - https://bit.ly/OldQB64
Reply
#11
Quote:Thread Review (Newest First)
Posted by eoredson - Today 06:02 PM
Did I say there was any advantage in using Field over Type? No.



Did I say, you said there was any advantage in using Field over Type? No. Big Grin

I was merely seeking an answer and you have answered.

Thank you.



(Why is the quote button not working? Sheez all this work to copy and paste a quote... Tongue)
B += x
Reply
#12
Ok, want to play a game?

Quote:Did I say, you said there was any advantage in using Field over Type?

Did I say, did you say, I said there was any advantage in using Field over Type?

(sounds recursive to me)...

Erik.

btw:
https://www.youtube.com/watch?v=FxLcmTCtvUQ
dndbbs project:

Links to my MUD: (strictly 16-bit); AKA XP:

Dndbbs executables
http://www.filegate.net/pdn/pdnbasic/dnd50a1e.zip

Dndbbs source
http://www.filegate.net/pdn/pdnbasic/dnd50a1s.zip

Dndbbs upgrade
http://www.filegate.net/pdn/pdnbasic/dnd50a1u.zip

DNDDOOR - https://bit.ly/EriksDNDDoor DUNGEON - https://bit.ly/EriksDungeon
Interpreter - https://bit.ly/EriksSICK Hex Editor - https://bit.ly/EriksHexEditor Utilities - https://bit.ly/EriksUtils
QB45 files: - https://bit.ly/EriksQB45 QB64shell - https://bit.ly/QB64shell Some old QB64 versions: - https://bit.ly/OldQB64
Reply