For a computer science project/test thing I have to make this program creating a database stored in a random access file. We have to include a bunch of different options that the user can choose and one is to sort the database by atleast 2 methods. We've learned all about merge sort and bubble sort and all that with arrays, but I'm not sure on how to sort files. I've been told that I have to put the contents of the file into an array which makes sense to me but I can't think of how that should/would be done. any help here would be appreciated. Thanks
Jared
Need help with random files and sorting them
Moderators:Administrator, Global Moderator
Re: Need help with random files and sorting them
If you are going to use RANDOM access for a file, you'll need to know "how the records are structured".
'An example of a record's data structure
Type ClientStruct
Fullname as String * 50
Age as Integer
Salary as Single
End Type
Then it's a matter of saving it to the array and sorting it.
'An example (not including the IO syntax nor
'the sorting routines...since you have already
'learned them.)
Hopefully, this will help you.
--MiggyD
'An example of a record's data structure
Type ClientStruct
Fullname as String * 50
Age as Integer
Salary as Single
End Type
Then it's a matter of saving it to the array and sorting it.
'An example (not including the IO syntax nor
'the sorting routines...since you have already
'learned them.)
Note that you have different kinds of information stored into that array. Don't confuse it with DIM SomeString$(x, x). This kind of dimensionalizing will only allow strings, but TYPE allows other kinds to be mixed with it.'Random File Data Structure
TYPE ClientStruct
FullName AS STRING * 50
Age AS INTEGER
Salary AS SINGLE
END TYPE
'Make some room in memory for the "Clients" array
'and have it set up to accept information based
'on the same type(s) of data that is in the
' "ClientStructure" above.
DIM Clients(1 TO 3) AS ClientStruct
CLS
'Gather information to store in the array.
FOR Cycle = 1 TO 3
INPUT "Enter Client Name:", Clients(Cycle).FullName
INPUT "Enter Client Age: ", Clients(Cycle).Age
INPUT "Enter Client Pay: ", Clients(Cycle).Salary
PRINT
NEXT
PRINT STRING$(60, 220)
'Display the information that is stored in each array.
FOR Cycle = 1 TO 3
PRINT Clients(Cycle).FullName
PRINT Clients(Cycle).Salary
PRINT Clients(Cycle).Age
PRINT
NEXT
PRINT STRING$(60, 220)
'Shows that you can work with numbers in an array
'that has been TYPE casted...
PRINT "Total Salaries: ";
FOR CycleAgain = 1 TO 3
TotalSal = TotalSal + Clients(CycleAgain).Salary
NEXT
PRINT TotalSal
END
Hopefully, this will help you.
--MiggyD
Re: Need help with random files and sorting them
Hey, thanks for your help. I actually figured it out today in class but your method seemed a lot easier and more efficient than mine so I'll probably use your way of doing it. Thanks for you help!
Zymatic a.k.a Jared
Zymatic a.k.a Jared