11-04-2023, 12:42 PM
(11-04-2023, 07:44 AM)PhilOfPerth Wrote: Thanks to those who tried to help me, but...
I guess I'm too old or too dense, or both, to make sense of any of the examples.
I can't get my head around the Type structures etc.
So I guess I'll go back to my (very primitive) original plan (crawls back into cave and pulls bush across doorway).
The responses were very much appreciated.
Give this a shot -- it's as simple as they come, with no Types or anything fancy. Just a file, a string, and some minor GET/PUT statements at work:
Code: (Select All)
CONST Length_of_Data = 30 'set a constant length for your record size
OPEN "temp.txt" FOR RANDOM AS #1 LEN = Length_of_Data 'Set that length for the file you're working with
DIM My_Junk AS STRING * Length_of_Data 'And create a string to hold your data the same size.
'Now, let's PUT some data into that file
My_Junk = "Hello World. #1 Record."
PUT #1, 1, My_Junk
My_Junk = "My name is Steve. #2 Record."
PUT #1, 2, My_Junk
My_Junk = "This is a demo! #3 Record."
PUT #1, 3, My_Junk
My_Junk = "Hiyas Phil! #4 Record."
PUT #1, 4, My_Junk
My_Junk = "I need coffee! #5 Record."
PUT #1, 5, My_Junk
My_Junk = "I'm finished here. #6 Record."
PUT #1, 6, My_Junk
'Did you notice where we use the record number as the 2nd element in that PUT statement?
'Now, let's get that random data back and print it ot the screen.
'First, in order from start to finish...
FOR i = 1 TO 6
GET #1, i, My_Junk 'Notice that we GET the record via that 2nd parameter as well
PRINT i, My_Junk
NEXT
PRINT
PRINT
DO
INPUT "Now, which record would you like to pull out randomly? =>"; record
IF record = 0 OR record > 6 THEN END
GET #1, record, My_Junk
PRINT "Record #"; record; ":"; My_Junk
LOOP
'And that's all there is to it!