In this post I expand on the Action! record data type. A record is a combination of multiple data types. It is declared as a TYPE, then a variable of that type is initialized just like it would be with other types such as BYTE, CARD, and INT. Why would you need this? To group common elements together such as a date, or an address.
Declaring a record type takes the following syntax (type definition followed by variable declaration):
TYPE type_name=[ variable_type variable_name ... ] type_name variable_name
Example:
TYPE date=[CARD year BYTE month, day] date birthday
Once declared each element of the variable can be accessed through the main variable name:
birthday.year birthday.month birthday.day
Complete Source
In this example I will group a CARD and two BYTEs in a record to form a date. It’s short and well commented so I won’t break it down:
MODULE ; Declare custom date type ; Consists of a CARD and two BYTEs TYPE tDate=[CARD cYear BYTE bMonth,bDay] ; Main Routine PROC Main() ; Declare a record from defined date type tDate rDate ; Setup screen Poke(82,0) Put($7D) PutE() PrintE("-[Record]-------------------------------") ; Get year, store in record Print("Date: Year?") rDate.cYear=InputC() ; Get month, store in record Print(" Month?") rDate.bMonth=InputB() ; Date day, store in record Print(" Day?") rDate.bDay=InputB() PutE() ; Print date from record reformatted PrintF("Date: %U.%B.%B%E%E", rDate.cYear, rDate.bMonth, rDate.bDay) ; Print each component of record PrintE("Record:") PrintF(" rDate.cYear=%U%E",rDate.cYear) PrintF(" rDate.bMonth=%B%E",rDate.bMonth) PrintF(" rDate.bDay=%B%E",rDate.bDay) RETURN