Here is some sample code... but I get an error and it's been too long since I've delt with records to figure what I'm doing wrong.
[B]Type[/B]
..rooms = [B]Record[/B]
....name : [B]String[20][/B];
....descpt1, descpt2 : [B]String[/B];
..[B]end[/B];
[B]Var[/B]
..fname : [B]file[/B];
[B]Begin[/B]
..assign(fname, 'rooms.dat');
..readln(rooms.name); [Red][Italic]<---- This is were I get my error, it says it is expecting a '(' after the word 'rooms'. I'm attempting to read input to store into rooms.name... what's going on here?? What am I missing?[/Italic][/Red]
[B]end[/B];
Any help will be appreciated... thanks!
Mr. El Moe
Comments
:
:
: [B]Type[/B]
: ..rooms = [B]Record[/B]
: ....name : [B]String[20][/B];
: ....descpt1, descpt2 : [B]String[/B];
: ..[B]end[/B];
:
: [B]Var[/B]
: ..fname : [B]file[/B];
:
: [B]Begin[/B]
: ..assign(fname, 'rooms.dat');
: ..readln(rooms.name); [Red][Italic]<---- This is were I get my error, it says it is expecting a '(' after the word 'rooms'. I'm attempting to read input to store into rooms.name... what's going on here?? What am I missing?[/Italic][/Red]
: [B]end[/B];
:
:
: Any help will be appreciated... thanks!
:
: Mr. El Moe
:
Your problem is that you've declared a type called rooms, but you've not
declared a variable based on that type.
Pascal works with variables only.
TYPE Rooms = RECORD
Name, Descrpt1, Descrpt2 : STRING;
END; { of type declaration}
Now you should declare variable based on that type :
VAR MyRoom : Rooms;
BEGIN
Assign(FName, 'rooms.DAT');
Reset(FName);
ReadLN(FName, MyRoom);
{reads the entire record from file}
END.