Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Pascal Database (Had to make new thread)

EluxElux Member Posts: 15
[b]Sorry I had to create a new thread as it only allows 10 posts per thread[/b]

My thread can be found here : http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=16&MsgID=327447&Setting=A9999F0001

[b]Thanks for your last reply phat nat :)[/b]

I've read over your reply and I'm not really understanding what to do I've had a play around with the code you provided but really stuck in gettting it to work - really sorry :(

«1

Comments

  • Phat NatPhat Nat Member Posts: 757
    : [b]Sorry I had to create a new thread as it only allows 10 posts per thread[/b]
    :
    : My thread can be found here : http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=16&MsgID=327447&Setting=A9999F0001
    :
    : [b]Thanks for your last reply phat nat :)[/b]
    :
    : I've read over your reply and I'm not really understanding what to do I've had a play around with the code you provided but really stuck in gettting it to work - really sorry :(
    :

    It's all a learning experience. Just re-read my post a few times, then try to convert it to code. Just go step-by-step. If you get stuck, post what you've come up with and I'll help you along.

    Phat Nat

  • EluxElux Member Posts: 15
    [b]I've been going over what you have said - thanks phat nat[/b]

    [italic]You need to write code to do the following:
    Make a variable (ex. StartPoint : Integer;)
    If you set a StartPoint to 0, then you can put this into your procedure as a starting search point. Save the result from Runner_Search1 into the StartPoint variable.
    If a record that matches is found, then StartPoint will now point to that array #.
    Now if you keep looping your search until your starting point is equal to -1, then you will be able to access all the records on by one.[/italic]

    I've come up with the code below....

    [code]Program RunnerDatabase;

    uses crt;

    const NAME_CHARS = 30;
    NUM_CHARS = 4;

    type RunnerRec = record
    RunnerNo : string[NUM_CHARS];
    RunnerName : string[NAME_CHARS];
    FinishTime : longInt;
    end;

    var RunnerArray : array [0..99] of RunnerRec;
    ch : Char;
    RecNo : integer;
    loopcount : integer;
    Hours, Minutes, Seconds, TimeinSeconds : longInt;
    runner_num_search, runner_name_search : String;
    i : 0..99;
    SearchResult : Byte; { Holds the array # result of the search }

    FUNCTION Runner_Search1(RunnerNo : String; Start : Byte) : Integer;
    var
    counter : Byte;
    Startpoint : integer;
    begin
    { If no runners match, then it will return -1 }
    Runner_Search1 := -1;
    Startpoint := 0

    { Check all the records for that runner number }
    For Counter := Start to RecNo-1 Do
    If RunnerArray[Counter].RunnerNo = RunnerNo Then
    Begin
    Runner_Search1 := Counter;
    Startpoint := Runner_Search1;
    Break;
    End;
    end;

    FUNCTION Runner_Search2(RunnerNo : String; Start : Byte) : Integer;
    var
    counter : Byte;
    Startpoint : integer;
    begin
    { If no runners match, then it will return -1 }
    Runner_Search2 := -1;
    Startpoint := 0

    { Check all the records for that runner number }
    For Counter := Start to RecNo-1 Do
    If RunnerArray[Counter].RunnerName = RunnerName Then
    Begin
    Runner_Search1 := Counter;
    Startpoint := Runner_Search2;
    Break;
    End;
    end;

    Begin
    RunnerArray[0].RunnerNo := '1';
    RunnerArray[0].RunnerName := 'Jim';
    RunnerArray[0].FinishTime := 60;
    RunnerArray[1].RunnerNo := '2';
    RunnerArray[1].RunnerName := 'Dave';
    RunnerArray[1].FinishTime := 120;
    RunnerArray[2].RunnerNo := '3';
    RunnerArray[2].RunnerName := 'Steven';
    RunnerArray[2].FinishTime := 150;
    RecNo := 3;
    repeat
    clrscr;
    gotoxy(15,4);
    writeln('** R U N N E R S D A T A B A S E **');
    gotoxy(15,6);
    writeln('Option 1 - Add a new Record');
    gotoxy(15,7);
    writeln('Option 2 - Search by Runner Number');
    gotoxy(15,8);
    writeln('Option 3 - Search by Runner Name');
    gotoxy(15,9);
    writeln('Option 4 - Search by Record Number');
    gotoxy(15,10);
    writeln('Option 5 - Display complete set of Records');
    gotoxy(15,12);
    writeln('Q or q to Quit');
    gotoxy(15,14);
    writeln('Please select an option from the Menu above');
    ch:=readkey;

    case ch of
    '1': Begin
    clrscr;
    gotoxy(17,5);
    writeln('** I N P U T I N G N E W R E C O R D S **');
    gotoxy(26,7);
    writeln('---ADD A NEW RECORD---');
    gotoxy(15,9);
    writeln('Please enter the runners number:');
    gotoxy(50,9);
    readln(RunnerArray[RecNo].RunnerNo);
    gotoxy(15,10);
    writeln('Please enter runners name:');
    gotoxy(50,10);
    readln(RunnerArray[RecNo].RunnerName);
    gotoxy(15,11);
    write('Please enter the finish time using hh mm ss');
    gotoxy(50,11);
    readln(Hours);
    gotoxy(53,12);
    readln(Minutes);
    gotoxy(56,12);
    readln(Seconds);
    TimeinSeconds := Hours * 3600 + Minutes * 60 + Seconds * 1;
    RunnerArray[RecNo].FinishTime := TimeinSeconds;
    RecNo := RecNo + 1;
    end;

    '2': Begin
    clrscr;
    gotoxy(20,5);
    writeln('** S E A R C H R E C O R D S **');
    gotoxy(21,7);
    writeln('---SEARCH BY RUNNER NUMBER---');
    gotoxy(15,9);
    writeln('Please enter Runner Number:');
    gotoxy(44,9);
    readln(runner_num_search);
    SearchResult := Runner_Search1(runner_num_search);
    gotoxy(15,11);
    writeln('Runner #',runner_num_search,' is at array record ',SearchResult);
    ch:=readkey;
    end;

    '3': Begin
    clrscr;
    gotoxy(20,5);
    writeln('** S E A R C H R E C O R D S **');
    gotoxy(22,7);
    writeln('---SEARCH BY RUNNER NAME---');
    gotoxy(15,9);
    writeln('Please enter Runner Name:');
    gotoxy(44,9);
    readln(runner_name_search);
    SearchResult := Runner_Search2(runner_name_search);
    gotoxy(15,11);
    writeln('Runner ',runner_name_search,' is at array record ',SearchResult);
    ch:=readkey;
    end;

    '4': Begin
    clrscr;
    gotoxy(20,5);
    writeln('** S E A R C H R E C O R D S **');
    gotoxy(21,7);
    writeln('---SEARCH BY RECORD NUMBER---');
    gotoxy(15,9);
    write('Now choose a record to display from 0 to 99: ');
    readln(i);
    gotoxy(15,11);
    writeln('Here are the details of record #',i,':');
    gotoxy(15,13);
    writeln('Runner Number: ', RunnerArray[i].RunnerNo);
    gotoxy(15,14);
    writeln('Runner Name: ', RunnerArray[i].RunnerName);
    Minutes := RunnerArray[i].FinishTime div 60;
    Seconds:= RunnerArray[i].FinishTime mod 60;
    Hours := Minutes div 60;
    Minutes := Minutes mod 60;
    gotoxy(15,15);
    write('Finish time: ');
    writeln(Hours, ':', Minutes, ':', Seconds);
    ch:=readkey;
    end;


    '5': Begin
    clrscr;
    gotoxy(8,5);
    writeln('** D I S P L A Y C O M P L E T E S E T O F R E C O R D S **');
    writeln;
    for loopcount := 0 to RecNo-1 do
    Begin
    write(RunnerArray[loopcount].RunnerNo, ' ');
    write(RunnerArray[loopcount].RunnerName, ' ');
    Minutes := RunnerArray[loopcount].FinishTime div 60;
    Seconds:= RunnerArray[loopcount].FinishTime mod 60;
    Hours := Minutes div 60;
    Minutes := Minutes mod 60;
    writeln(Hours, ':', Minutes, ':', Seconds);
    end;
    ch:=readkey;
    end;

    'Q','q': Begin
    gotoxy(15,16);
    writeln('Press return to Quit');
    readln;
    end;
    end;

    until (ch='Q') or (ch='q');
    end.[/code]
  • Phat NatPhat Nat Member Posts: 757
    I don't think you're quite getting it. This looks like the same code you posted before. Let's think smaller. First off, let's get rid of all the other code, so we can focus completely on the search procedure and for now, we are only going to concentrate on one of the search procedures. However in order for us to do that we will need some input data to work with, so we will keep the record listings that you have made and we will add a few to it that doubles a Runner No (Since our goal is to be able to display more that one runner with the same number)
    You'll notice that there are now three No 2. Also, all that we have listed is the Search routine.

    [code]Program RunnerDatabase;
    uses crt;

    const NAME_CHARS = 30;
    NUM_CHARS = 4;

    type RunnerRec = record
    RunnerNo : string[NUM_CHARS];
    RunnerName : string[NAME_CHARS];
    FinishTime : longInt;
    end;

    var RunnerArray : array [0..99] of RunnerRec;
    ch : Char;
    RecNo : integer;
    loopcount : integer;
    runner_num_search : String;
    i : 0..99;
    SearchResult : Byte; { Holds the array # result of the search }
    [b]StartPoint : Integer;[/b]

    FUNCTION Runner_Search1(RunnerNo : String; Start : Byte) : Integer;
    var
    counter : Byte;
    begin
    { If no runners match, then it will return -1 }
    Runner_Search1 := -1;

    { Check all the records for that runner number }
    For Counter := Start to RecNo-1 Do
    If RunnerArray[Counter].RunnerNo = RunnerNo Then
    Begin
    Runner_Search1 := Counter;
    Break;
    End;
    end;

    Begin
    RunnerArray[0].RunnerNo := '1';
    RunnerArray[0].RunnerName := 'Jim';
    RunnerArray[0].FinishTime := 60;
    RunnerArray[1].RunnerNo := '2';
    RunnerArray[1].RunnerName := 'Dave';
    RunnerArray[1].FinishTime := 120;
    RunnerArray[2].RunnerNo := '4';
    RunnerArray[2].RunnerName := 'Steven';
    RunnerArray[2].FinishTime := 150;
    RunnerArray[3].RunnerNo := '2';
    RunnerArray[3].RunnerName := 'Ronald';
    RunnerArray[3].FinishTime := 170;
    RunnerArray[4].RunnerNo := '5';
    RunnerArray[4].RunnerName := 'Jim';
    RunnerArray[4].FinishTime := 210;
    RunnerArray[5].RunnerNo := '2';
    RunnerArray[5].RunnerName := 'Roger';
    RunnerArray[5].FinishTime := 350;
    RecNo := 6;

    gotoxy(20,5);
    writeln('** S E A R C H R E C O R D S **');
    gotoxy(21,7);
    writeln('---SEARCH BY RUNNER NUMBER---');
    gotoxy(15,9);
    writeln('Please enter Runner Number:');
    gotoxy(44,9);
    readln(runner_num_search);

    [b]StartPoint := 0;[/b]
    SearchResult := Runner_Search1(runner_num_search[b],StartPoint[/b]);
    gotoxy(15,11);
    writeln('Runner #',runner_num_search,' is at array record ',SearchResult);

    ch:=readkey;
    end.[/code]


    Okay, now notice where I have put the startpoint. It is NOT within the procedure, it just tells the procedure where to start the search from.
    Now you need to apply this to the code above:

    [code][italic]So, we can simplifiy it to this:
    1) Set our search starting point to 0 [b] DONE [/b]
    2) Run our search, beginning at StartPoint [b] DONE [/b]
    3) If result is -1 then goto step #7
    4) display information for record[result] [b] DONE [/b]
    5) set our search starting point to result
    6) goto step #2
    7) all the records have been displayed
    [/italic][/code]

    You'll notice that three of the steps have been done, however we are missing some steps. Try to fill in each step. Notice that Step 6 says Goto Step #2, this means you are going to need to write a loop (Either REPEAT...UNTIL or WHILE...DO)

    Phat Nat

  • EluxElux Member Posts: 15
    Thanks for your last reply Phat Nat, I've gone over what you've said to do.

    [code]1) Set our search starting point to 0 DONE
    2) Run our search, beginning at StartPoint DONE
    3) If result is -1 then goto step #7
    4) display information for record[result] DONE
    5) set our search starting point to result
    6) goto step #2
    7) all the records have been displayed[/code]

    I wasn't sure on step Five since we had set it zero I didnt think this was needed. I put the loop in like you suggested.

    [code] '2': Begin
    clrscr;
    gotoxy(20,5);
    writeln('** S E A R C H R E C O R D S **');
    gotoxy(21,7);
    writeln('---SEARCH BY RUNNER NUMBER---');
    gotoxy(15,9);
    writeln('Please enter Runner Number:');
    gotoxy(44,9);
    readln(runner_num_temp);
    Repeat
    StartPoint := 0;
    SearchResult := RunnerNo_Search(runner_num_temp,StartPoint);
    Until SearchResult = -1
    If SearchResult := 1 Then
    Begin
    write(RunnerArray[SearchResult].RunnerNo, ' ');
    write(RunnerArray[SearchResult].RunnerName, ' ');
    Minutes := RunnerArray[SearchResult].FinishTime div 60;
    Seconds:= RunnerArray[SearchResult].FinishTime mod 60;
    Hours := Minutes div 60;
    Minutes := Minutes mod 60;
    writeln(Hours, ':', Minutes, ':', Seconds);
    ch:=readkey;
    end;
    end;[/code]

  • Phat NatPhat Nat Member Posts: 757
    : Thanks for your last reply Phat Nat, I've gone over what you've said to do.
    :
    : [code]1) Set our search starting point to 0 DONE
    : 2) Run our search, beginning at StartPoint DONE
    : 3) If result is -1 then goto step #7
    : 4) display information for record[result] DONE
    : 5) set our search starting point to result
    : 6) goto step #2
    : 7) all the records have been displayed[/code]
    :
    : I wasn't sure on step Five since we had set it zero I didnt think this was needed. I put the loop in like you suggested.
    :
    : [code] '2': Begin
    : clrscr;
    : gotoxy(20,5);
    : writeln('** S E A R C H R E C O R D S **');
    : gotoxy(21,7);
    : writeln('---SEARCH BY RUNNER NUMBER---');
    : gotoxy(15,9);
    : writeln('Please enter Runner Number:');
    : gotoxy(44,9);
    : readln(runner_num_temp);
    : Repeat
    : StartPoint := 0;
    : SearchResult := RunnerNo_Search(runner_num_temp,StartPoint);
    : Until SearchResult = -1
    : If SearchResult := 1 Then
    : Begin
    : write(RunnerArray[SearchResult].RunnerNo, ' ');
    : write(RunnerArray[SearchResult].RunnerName, ' ');
    : Minutes := RunnerArray[SearchResult].FinishTime div 60;
    : Seconds:= RunnerArray[SearchResult].FinishTime mod 60;
    : Hours := Minutes div 60;
    : Minutes := Minutes mod 60;
    : writeln(Hours, ':', Minutes, ':', Seconds);
    : ch:=readkey;
    : end;
    : end;[/code]

    So does it work? From what I can see I think it would give a compile error and even after that it would go into an endless loop.

    On my last post I gave you simplified code. Right now you are trying to get a section working, but it gets complicated by everything else. Sometimes the easiest way (if possible) is to concentrate on just the section that you are working on. This way you can keep your focus & then transfer into your main code once you are done. So I would suggest going back to my last post and working that area out. It will tell you as soon as you run it if the search is working properly.

    Okay, well you did try and your attempt looks good. Although your coed doesn't match the layout described above. Let's look:

    * Step #1, 2 & 3 look good. you set the seacrh to 0, run the search and check if it's at the end of the records.
    * Step #4 is there, although once we work through the rest of it, we will find a problem.
    * Step #5 you said was redundant, although that is not true
    * Step #6. Okay, notice where this step tells you to go. It takes us back to Step#2, not Step#1. Right now, when we repeat, we are running step#1 again, which we don't want. We want to start where we left off. Step#1 should only be run once!

    TRy it again & make sure that it compiles when you are done. Don't try to write the code on the message board, write it in a compiler because then you can test it.

    Hope this helps,
    Phat Nat

  • EluxElux Member Posts: 15
    [b]Thanks for your help Phat Nat[/b]

    I wasn't really understanding how to do it, I can imagine it was easy once I knew how but I'm still a beginner lol. I went over al the resources and spend all afternoon and I think I've come up with something that works just as well, I've ran it and it seems to work ok :)

    I was wondering if you could help me with something else, I would like it so that on 'Option 5 - Display all records' that it only displays ten at a time so they have to press enter to see the next ten, is that possible and if so how?

    Heres is the code I have so far:

    [code]Program RunnerDatabase;

    uses crt;

    const NAME_CHARS = 30;
    NUM_CHARS = 4;

    type RunnerRec = record
    RunnerNo : string[NUM_CHARS];
    RunnerName : string[NAME_CHARS];
    FinishTime : longInt;
    end;

    var RunnerArray : array [0..99] of RunnerRec;
    ch : Char;
    RecNo : integer;
    loopcount : integer;
    Hours, Minutes, Seconds, TimeinSeconds : longInt;
    runner_num_search, runner_name_search : String;
    i : 0..99;
    SearchResult : Byte; { Holds the array # result of the search }

    FUNCTION Runner_Search1(RunnerNo : String) : Integer;
    var
    counter : Byte;
    begin
    { If no runners match, then it will return -1 }
    Runner_Search1 := -1;

    { Check all the records for that runner number }
    For Counter := 0 to RecNo-1 Do
    If RunnerArray[Counter].RunnerNo = RunnerNo Then
    Runner_Search1 := Counter;
    end;

    FUNCTION Runner_Search2(RunnerName : String) : Integer;
    var
    counter : Byte;
    begin
    { If no runners match, then it will return -1 }
    Runner_Search2 := -1;

    { Check all the records for that runner name }
    For Counter := 0 to RecNo-1 Do
    If RunnerArray[Counter].RunnerName = RunnerName Then
    Runner_Search2 := Counter;
    end;

    Begin
    RunnerArray[0].RunnerNo := '1';
    RunnerArray[0].RunnerName := 'Jim';
    RunnerArray[0].FinishTime := 60;
    RunnerArray[1].RunnerNo := '2';
    RunnerArray[1].RunnerName := 'Dave';
    RunnerArray[1].FinishTime := 120;
    RunnerArray[2].RunnerNo := '3';
    RunnerArray[2].RunnerName := 'Steven';
    RunnerArray[2].FinishTime := 150;
    RunnerArray[3].RunnerNo := '2';
    RunnerArray[3].RunnerName := 'Dave';
    RunnerArray[3].FinishTime := 170;
    RunnerArray[4].RunnerNo := '5';
    RunnerArray[4].RunnerName := 'Jim';
    RunnerArray[4].FinishTime := 210;
    RunnerArray[5].RunnerNo := '2';
    RunnerArray[5].RunnerName := 'Dave';
    RunnerArray[5].FinishTime := 350;
    RunnerArray[6].RunnerNo := '1';
    RunnerArray[6].RunnerName := 'Jim';
    RunnerArray[6].FinishTime := 60;
    RunnerArray[7].RunnerNo := '2';
    RunnerArray[7].RunnerName := 'Dave';
    RunnerArray[7].FinishTime := 120;
    RunnerArray[8].RunnerNo := '3';
    RunnerArray[8].RunnerName := 'Steven';
    RunnerArray[8].FinishTime := 150;
    RunnerArray[9].RunnerNo := '2';
    RunnerArray[9].RunnerName := 'Dave';
    RunnerArray[9].FinishTime := 170;
    RunnerArray[10].RunnerNo := '5';
    RunnerArray[10].RunnerName := 'Jim';
    RunnerArray[10].FinishTime := 210;
    RunnerArray[11].RunnerNo := '2';
    RunnerArray[11].RunnerName := 'Dave';
    RunnerArray[11].FinishTime := 350;
    RunnerArray[12].RunnerNo := '2';
    RunnerArray[12].RunnerName := 'Dave';
    RunnerArray[12].FinishTime := 120;

    RecNo := 5;
    repeat
    clrscr;
    gotoxy(15,4);
    writeln('** R U N N E R S D A T A B A S E **');
    gotoxy(15,6);
    writeln('Option 1 - Add a new Record');
    gotoxy(15,7);
    writeln('Option 2 - Search by Runner Number');
    gotoxy(15,8);
    writeln('Option 3 - Search by Runner Name');
    gotoxy(15,9);
    writeln('Option 4 - Search by Record Number');
    gotoxy(15,10);
    writeln('Option 5 - Display complete set of Records');
    gotoxy(15,12);
    writeln('Q or q to Quit');
    gotoxy(15,14);
    writeln('Please select an option from the Menu above');
    ch:=readkey;

    case ch of
    '1': Begin
    clrscr;
    gotoxy(17,5);
    writeln('** I N P U T I N G N E W R E C O R D S **');
    gotoxy(26,7);
    writeln('---ADD A NEW RECORD---');
    gotoxy(15,9);
    writeln('Please enter the runners number:');
    gotoxy(50,9);
    readln(RunnerArray[RecNo].RunnerNo);
    gotoxy(15,10);
    writeln('Please enter runners name:');
    gotoxy(50,10);
    readln(RunnerArray[RecNo].RunnerName);
    gotoxy(15,11);
    write('Please enter the finish time using hh mm ss');
    gotoxy(50,11);
    readln(Hours);
    gotoxy(53,12);
    readln(Minutes);
    gotoxy(56,12);
    readln(Seconds);
    TimeinSeconds := Hours * 3600 + Minutes * 60 + Seconds * 1;
    RunnerArray[RecNo].FinishTime := TimeinSeconds;
    RecNo := RecNo + 1;
    end;

    '2': Begin
    clrscr;
    gotoxy(20,5);
    writeln('** S E A R C H R E C O R D S **');
    gotoxy(21,7);
    writeln('---SEARCH BY RUNNER NUMBER---');
    gotoxy(15,9);
    writeln('Please enter Runner Number:');
    gotoxy(44,9);
    readln(runner_num_search);
    SearchResult := Runner_Search1(runner_num_search);
    gotoxy(15,11);
    writeln('Runner #',runner_num_search,' is at array record ',SearchResult);
    ch:=readkey;
    end;

    '3': Begin
    clrscr;
    gotoxy(20,5);
    writeln('** S E A R C H R E C O R D S **');
    gotoxy(22,7);
    writeln('---SEARCH BY RUNNER NAME---');
    gotoxy(15,9);
    writeln('Please enter Runner Name:');
    gotoxy(44,9);
    readln(runner_name_search);
    SearchResult := Runner_Search2(runner_name_search);
    gotoxy(15,11);
    writeln('Runner ',runner_name_search,' is at array record ',SearchResult);
    ch:=readkey;
    end;

    '4': Begin
    clrscr;
    gotoxy(20,5);
    writeln('** S E A R C H R E C O R D S **');
    gotoxy(21,7);
    writeln('---SEARCH BY RECORD NUMBER---');
    gotoxy(15,9);
    write('Now choose a record to display from 0 to 99: ');
    readln(i);
    gotoxy(15,11);
    writeln('Here are the details of record #',i,':');
    gotoxy(15,13);
    writeln('Runner Number: ', RunnerArray[i].RunnerNo);
    gotoxy(15,14);
    writeln('Runner Name: ', RunnerArray[i].RunnerName);
    Minutes := RunnerArray[i].FinishTime div 60;
    Seconds:= RunnerArray[i].FinishTime mod 60;
    Hours := Minutes div 60;
    Minutes := Minutes mod 60;
    gotoxy(15,15);
    write('Finish time: ');
    writeln(Hours, ':', Minutes, ':', Seconds);
    ch:=readkey;
    end;


    '5': Begin
    clrscr;
    gotoxy(8,5);
    writeln('** D I S P L A Y C O M P L E T E S E T O F R E C O R D S **');
    writeln;
    for loopcount := 0 to RecNo-1 do
    Begin
    write(RunnerArray[loopcount].RunnerNo, ' ');
    write(RunnerArray[loopcount].RunnerName, ' ');
    Minutes := RunnerArray[loopcount].FinishTime div 60;
    Seconds:= RunnerArray[loopcount].FinishTime mod 60;
    Hours := Minutes div 60;
    Minutes := Minutes mod 60;
    writeln(Hours, ':', Minutes, ':', Seconds);
    end;
    ch:=readkey;
    end;

    'Q','q': Begin
    gotoxy(15,16);
    writeln('Press return to Quit');
    readln;
    end;
    end;

    until (ch='Q') or (ch='q');
    end.[/code]


  • Phat NatPhat Nat Member Posts: 757
    : I was wondering if you could help me with something else, I would like it so that on 'Option 5 - Display all records' that it only displays ten at a time so they have to press enter to see the next ten, is that possible and if so how?

    Make a counter variable and have it add one every time through your loop. Then you can use the MODulus function to see if the counter is directly divisible by ten, and if so then, you can pause. Here is an example on the MOD function:

    [code]
    If Counter MOD(10) = 0 Then Readkey;
    [/code]

    Phat Nat
  • EluxElux Member Posts: 15
    : [code]
    : If Counter MOD(10) = 0 Then Readkey;
    : [/code]

    I've put the counter in and put that line of code in and it works :) How could I get it so that it clears the previous ten and displays the next set of 10. At the moment the next then just appears under it.

    [code] '5': Begin
    clrscr;
    gotoxy(8,5);
    writeln('** D I S P L A Y C O M P L E T E S E T O F R E C O R D S **');
    writeln;
    writeln('Here is a list of stored records:');
    writeln;
    writeln('Please note records are displayed in blocks of ten.');
    writeln('Press RETURN to scroll through.');
    writeln;
    for loopcount := 0 to RecNo-1 do
    Begin
    counter := counter + 1;
    write(RunnerArray[loopcount].RunnerNo, ' ');
    write(RunnerArray[loopcount].RunnerName, ' ');
    Minutes := RunnerArray[loopcount].FinishTime div 60;
    Seconds:= RunnerArray[loopcount].FinishTime mod 60;
    Hours := Minutes div 60;
    Minutes := Minutes mod 60;
    writeln(Hours, ':', Minutes, ':', Seconds);
    If Counter MOD(10) = 0 Then Readkey;
    end;
    ch:=readkey;
    end;[/code]



  • Phat NatPhat Nat Member Posts: 757
    : : [code]
    : : If Counter MOD(10) = 0 Then Readkey;
    : : [/code]
    :
    : I've put the counter in and put that line of code in and it works :) How could I get it so that it clears the previous ten and displays the next set of 10. At the moment the next then just appears under it.


    Why not add a CLRSCR call after the ReadKey call? ;)

    *Remember that you only want the screen cleared when the tenth record is hit, so it has to be only called when Counter MOD(10) = 0.

    Phat Nat
  • EluxElux Member Posts: 15
    : Why not add a CLRSCR call after the ReadKey call? ;)
    :
    : *Remember that you only want the screen cleared when the tenth record is hit, so it has to be only called when Counter MOD(10) = 0.
    :
    : Phat Nat

    I tried adding this in under it but it then only displays one record

«1
Sign In or Register to comment.