Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Indexed files
#14
(11-04-2023, 07:44 AM)PhilOfPerth Wrote: Thanks to those who tried to help me, but...  Huh
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!
Reply


Messages In This Thread
Indexed files - by PhilOfPerth - 11-03-2023, 11:21 PM
RE: Indexed files - by a740g - 11-03-2023, 11:40 PM
RE: Indexed files - by bplus - 11-03-2023, 11:44 PM
RE: Indexed files - by bplus - 11-03-2023, 11:50 PM
RE: Indexed files - by TerryRitchie - 11-03-2023, 11:55 PM
RE: Indexed files - by bplus - 11-03-2023, 11:55 PM
RE: Indexed files - by SMcNeill - 11-04-2023, 12:29 AM
RE: Indexed files - by bplus - 11-03-2023, 11:57 PM
RE: Indexed files - by JamesAlexander - 11-04-2023, 01:20 AM
RE: Indexed files - by PhilOfPerth - 11-04-2023, 01:39 AM
RE: Indexed files - by mnrvovrfc - 11-04-2023, 02:21 AM
RE: Indexed files - by PhilOfPerth - 11-04-2023, 07:44 AM
RE: Indexed files - by bplus - 11-04-2023, 11:54 AM
RE: Indexed files - by SMcNeill - 11-04-2023, 12:42 PM
RE: Indexed files - by Dimster - 11-04-2023, 01:57 PM
RE: Indexed files - by bplus - 11-04-2023, 04:50 PM
RE: Indexed files - by Kernelpanic - 11-04-2023, 11:13 PM
RE: Indexed files - by PhilOfPerth - 11-05-2023, 12:21 AM
RE: Indexed files - by bplus - 11-05-2023, 01:55 PM
RE: Indexed files - by PhilOfPerth - 11-05-2023, 11:31 PM



Users browsing this thread: 6 Guest(s)