Languages :: Pascal :: record numbers in pascal..... |
|||
| By: skitz0 |
Date: 28/04/2003 00:00:00 |
Points: 75 | Status: Answered Quality : Excellent |
|
right here goes....this is my project...and what i need to do is have a search procedure (which i have tried to do in procedure "view cand")..but the only way i can search for candidates is if i search for the record numbers....is there any way that i can search by the candidate number(candrecord.candnum) or is there any way in which i can view the record number when i list all the candidates....any help will be appreciated.... program assignment; uses crt; type candrecordtype = record name:string[40]; candnum:integer; centrenum:integer; subrefcode:string; origmark:integer; remarkmark:integer; request:boolean; origG:string; remarkG:string; yes:string; recnum;integer; end; var diskfile:file of candrecordtype; candrecord:candrecordtype; counter:integer; choice:integer; loop:integer; procedure open; begin assign (diskfile, 'c:\windows\desktop\work\record.dat'); reset (diskfile); end; procedure listcand; begin reset(diskfile); clrscr; writeln ('candidates in database'); for loop :=0 to (filesize(diskfile)-1) do begin seek(diskfile,loop); read(diskfile,candrecord); writeln ('candidate name : ',candrecord.name); writeln ('candidate number : ',candrecord.candnum); writeln; end; readln; end; procedure addcand; var yes:string; begin clrscr; writeln ('Add Candidate To Database'); writeln ('please enter candidate name'); readln (candrecord.name); writeln ('please enter candidate number'); readln (candrecord.candnum); writeln ('please enter centre number'); readln (candrecord.centrenum); writeln ('please enter subject reference code'); readln (candrecord.subrefcode); writeln ('please enter original mark'); readln (candrecord.origmark); writeln ('please enter re-mark (leave blank if not yet marked)'); readln (candrecord.remarkmark); repeat writeln ('did the centre request the script back? y/n'); readln (yes); if (yes='y') then candrecord.request:=true; if (yes='n') then candrecord.request:=false; until (yes='y') or (yes='n'); seek(diskfile,(filesize(diskfile))); write(diskfile,candrecord); writeln ('record saved'); readln; end; procedure viewcand; var number:integer; begin clrscr; writeln('enter candidate number'); readln (number); if number>(filesize(diskfile)-1) then begin writeln ('this record does not exist'); readln; end else begin reset(diskfile); seek(diskfile,number); read (diskfile,candrecord); with candrecord do begin writeln ('candidate name : ',name); writeln ('candidate number : ',candnum); writeln ('centre number : ',centrenum); writeln ('subject reference code : ',subrefcode); writeln ('origional mark : ',origmark); if remarkmark>0 then writeln ('remark : ',remarkmark) else writeln ('remark : N/A'); writeln; readln; end; end; end; begin repeat clrscr; open; writeln ('Ukab Database'); writeln ('1. add candidate to database'); writeln ('2. view all candidates'); writeln ('3. view individual candidate'); writeln ('4. exit'); readln (choice); case choice of 1:addcand; 2:listcand; 3:viewcand; 4:exit; end; until choice=4 end. |
|||
| By: VGR | Date: 28/04/2003 07:41:00 | Type : Answer |
|
| with direct access like in here, no. You need an index. Or to have sorted your records on candnum so that any algorithm can be used (dichotomy is first possibility) For now, assuming you've none of the above, the answer is : yes, you can, but in stead of accessing directly (on record number) a precise record (no search), you've to search in ALL the recoprds (or at least until the candnum searched for is found, trivially) something like read (diskfile,candrecord); if candrecord.candnum<>searchedvalue Then while (NOT Eof(diskfile)) AND (candrecord.candnum<>searchedvalue) Do read (diskfile,candrecord); // you get out either on positive candrecord.candnum=searchedvalue or on eof (not found) |
|||
| By: skitz0 | Date: 28/04/2003 07:57:00 | Type : Comment |
|
| erm....still the same....when i search it for the record number.....but not for the candidate number.... |
|||
| By: VGR | Date: 28/04/2003 09:27:00 | Type : Comment |
|
| sorry, but it should work. show your current code |
|||
| By: skitz0 | Date: 28/04/2003 09:37:00 | Type : Comment |
|
| erm...i got it runnin a different way now mate....but after trying your code a second time it does work (when i put it in the right place) hehe....so u get the points :) |
|||
| By: VGR | Date: 29/04/2003 05:03:00 | Type : Comment |
|
| tsssk tsssk tsssk :D thanks a lot |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








