Posted: Tue Nov 25, 2003 1:10 pm Post subject: [Tutorial] Records
A record is a structure of data with the same name but different subscripts. Structures are not a necessity for any program, but it will make your source look much more pretty.
If we were to create a database on each student in the school, we may need several arrays:
code:
var firstname :array 1.. 1400 of string
var lastname :array 1..1400 of string
var height: array 1..1400 of int
var age: array 1..1400 of int
var grade: array 1..1400 of int
var average: array 1..1400 of int
var haircolor: array 1..1400 of int
var gender: array 1..1400 of string
var eyecolor: array 1..1400 of string
as you can see, this is very annoying, not mentioning confusing if u were to access the info on a student
however, with records, this can be very easy
code:
type studentData:
record
firstname: string
lastname: string
height: int
age: int
grade:int
average:int
haircolor:int
gender: string
eyecolor: string
end record
now that student Data is a type, you can declare an array of it
code:
var student : array 1..1400 of studentData
to call up each elements of the structure
code:
student(1).age:=15
another great thing about records is that you can copy an entire record into another for example
code:
student(1):=student(2)
the structure of student(1) will now be the same as student(2)
well thats about it.
Sponsor Sponsor
Dan
Posted: Tue Nov 25, 2003 5:13 pm Post subject: (No subject)
thanks for the tutorial and i know have been whonting some bits so i gusse i will give you some for this better then spamming
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
AsianSensation
Posted: Tue Nov 25, 2003 6:20 pm Post subject: (No subject)
wow, dodge not spamming? Wait....I just saw a pig go flying across my window, wow, these things actually do happen.
anyways, always try to use records. Unless you are so good that you won't ever get confused with codes and what they do, and can handle large multi-dimensional arrays with ease, then use records, they are great for organization.
Andy
Posted: Tue Nov 25, 2003 7:01 pm Post subject: (No subject)
lol, dan got pissed, so i got scared... unlike some other disrespectful lil kids here... recursion is nxt
Mazer
Posted: Tue Nov 25, 2003 9:49 pm Post subject: (No subject)
nice tutorial. you can't tell, but i'm clapping right now. here, have some bits
Atma Weapon
Posted: Mon Dec 08, 2003 1:40 am Post subject: (No subject)
This tutorial has been extremely helpful. Take all my bits, with my thanks,
junkpro11
Posted: Sun May 09, 2004 10:42 pm Post subject: (No subject)
one question....if i want to store the input from the user for each category, like firstname i would use
get firstname
student(1).firstname:=firstname
is this correct?
if i want to make this into like a database, which allows users to create records....... do i use array 1..100 of studentdata (eg 100 students)?
how do i write each student file according to student number....like 10023.t or 15246.t etc
AsianSensation
Posted: Mon May 10, 2004 2:22 pm Post subject: (No subject)
code:
type StudentType :
record
FirstName : string
end record
var database : array 1 .. 100 of StudentType
for rep : 1 .. 100
get database (rep).FirstName
end for
use intstr to manipulate strings of the file name if you want a specific text file to be the student number of that student.
Sponsor Sponsor
junkpro11
Posted: Mon May 10, 2004 10:06 pm Post subject: (No subject)
code:
open: stremout, intstr(istudentnum).t, put
an error pops up saying "expression cannot be followed by a '.' "
Tony
Posted: Mon May 10, 2004 10:56 pm Post subject: (No subject)
Posted: Wed May 26, 2004 10:14 am Post subject: how to pass the record to procedure to procedure
since the record is made up by array, how can i declare the variable in the procedure?
i wanna the record can be used in a wider range?
need help!!!!
~.~
AsianSensation
Posted: Wed May 26, 2004 7:32 pm Post subject: Re: how to pass the record to procedure to procedure
lee_Amilghty wrote:
since the record is made up by array, how can i declare the variable in the procedure?
i wanna the record can be used in a wider range?
no, records are not made up of arrays. You can have an array of records, but doesn't mean it's made up of arrays.
secondly, what do you mean using records in a wider range?
if you want to pass record from procedure to procedure, it's best to just declare a global record, and have procedures and functions that changes it. That would be the easiest way.
Omicron91
Posted: Mon Dec 20, 2004 5:54 pm Post subject: (No subject)
Weird, I was just takign a break from making a program that used types/records, to bad I didn't see this about three hours ago, oh well, it worked out. Not done though.
code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
type Seat :
record
Price : real
Occupied : boolean
Number : int
Letter : string
Name : string
Select : boolean
end record
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var Auditorium : array 1 .. 20, 1 .. 25 of Seat
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var Chair : int := Pic.FileNew ("Chair.jpg")
var DarkChair : int := Pic.FileNew ("DarkChair.jpg")
var SoldChair : int := Pic.FileNew ("SoldChair.jpg")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var DisplayWin : int := Window.Open ("position:top;center,graphics:330;530,nobuttonbar,offscreenonly")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var font1 : int := Font.New ("Courier New:10")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var tempString : string
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var SaveFile : int
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure DrawAuditorium
for x : 1 .. 20
for y : 1 .. 25
if Auditorium (x, y).Occupied = false then
Pic.Draw (DarkChair, x * 15, y * 20, picMerge)
elsif Auditorium (x, y).Occupied = true then
Pic.Draw (SoldChair, x * 15, y * 20, picMerge)
end if
end for
end for
View.Update
end DrawAuditorium
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process SaveToDisk
open : SaveFile, "Backup.txt", put
loop
for x : 1 .. 20
for y : 1 .. 25
put : SaveFile, "Price : ", Auditorium (x, y).Price, " | Occupied : ", Auditorium (x, y).Occupied, " | Letter : ", Auditorium (x, y).Letter, " | Ticket Holder : ", Auditorium (x,
y).Name, " | Number : ", Auditorium (x, y).Number
end for
end for
exit
end loop
end SaveToDisk
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for x : 1 .. 20
for y : 1 .. 25
Auditorium (x, y).Price := 19.99
Auditorium (x, y).Occupied := false
Auditorium (x, y).Number := y
Auditorium (x, y).Letter := chr (x + 64)
Auditorium (x, y).Name := "N/A"
Auditorium (x, y).Select := false
end for
end for
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DrawAuditorium
Input.Pause
fork SaveToDisk
wtd
Posted: Mon Dec 20, 2004 7:10 pm Post subject: Re: how to pass the record to procedure to procedure
AsianSensation wrote:
if you want to pass record from procedure to procedure, it's best to just declare a global record, and have procedures and functions that changes it. That would be the easiest way.
No, it wouldn't.
This is never a good idea.
Andy
Posted: Mon Dec 20, 2004 7:33 pm Post subject: (No subject)