
-----------------------------------
haayyeess
Sat Oct 31, 2015 1:30 pm

Sorting a record by a user defined field
-----------------------------------
What is it you are trying to achieve?
I have a database program which currently only is holding a first and last name (in two different locations of a record).  I want the user to be able to sort added data by ANY field (I will be adding more).  Currently I have a sub receiving the users input into a temporary variable, but am not sure how to translate this choice into the record location/selection to sort within my sort routine.  I have been trying to store the name of the record location within a variable, and using it but it's not working... Can anyone provide suggestions?

EX:
Record
     First : string
     Last : string
end record

Get FieldChoice from user...
FieldChoice := "First"

sort routine...
if Record (Comparision).FieldChoice ....

I even tried using a pointer, but was unable to find success. My computer science teacher hasn't used them in years and is unable to provide valid support...

What is the problem you are having?
When sorting, my sorting loop complains that the location I am trying to swap "is not a field of record". 


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)




procedure Sort_Initiation (var Person : PERSON_ARRAY, var RecordCount : nat1, var TempData : string)

    %LOCAL VARIABLES
     % Temp var to store data until proved valid        
    
    colour (brightgreen)
    if RecordCount > 0 then %Data to sort
        put "So you are looking to sort some of your records..."
        put "Please enter the letter infront of the field you would like to sort"
        put "Alternatively, you can type 'exit' to return to the main menu"
        colour (white)
        get TempData : *
        if TempData = "exit" or TempData = "EXIT" then % Skip everything else and just exit
            %Skip rest and exit to menu
        elsif length (TempData) = 1 and 
            (TempData >= "a" and TempData = "A" and TempData 