This is slightly out of order as it should have been before the last post, but here it is.
There are many ways to output to the screen in Action!. There are several flavors of the Print procedure. There are versions specific to data types, and then there is a version that can handle multiple data types. On top of that, there are variants for outputting with and without an EOL (end of line). In addition to Print there is also a Put procedure.
Print Variants
- Print – Outputs literal text string or character array variable (without EOL)
- PrintE – Outputs literal text string or character array variable (with EOL)
- PrintB – Outputs byte value (without EOL)
- PrintBE – Outputs byte value (with EOL)
- PrintC – Outputs card value (without EOL)
- PrintCE – Outputs card value (with EOL)
- PrintI – Outputs integer value (without EOL)
- PrintIE – Outputs integer value (with EOL)
- PrintF – Outputs multiple value types with or without EOL. Short for formatted output.
Put Variants
- Put – Outputs a byte value
- PutE – Outputs and EOL
Demonstration
Here is a short program that demonstrates each variant, with a breakdown. The complete un-interrupted source will be presented at the end.
First we declare a new module. The MODULE directive tells the compiler that global variables follow. For simple programs this can be omitted as the compiler will implicitly define one if it is not found.
MODULE
Here I declare a variable of each type and initialize their values. Note that CHAR and BYTE can be interchanged. bChar is set to 65 which is the value of letter A.
BYTE bVal=[255] CARD cVal=[1024] INT iVal=[32767] CHAR ARRAY sVal(30)="Inverse ATASCII" CHAR bChar=[65]
This is the start of the main procedure. Every Action! program must have at least one procedure.
PROC Main()
This first example uses PrintE. This prints a character string followed by an EOL.
PrintE("Print Examples")
Next I use Print to display the text “Byte : “. No EOL is output since I don’t want the cursor returned to the next line yet.
Print("Byte : ")
Here I use PrintBE to display the byte in variable bVal, and follow it with an EOL.
PrintBE(bVal)
Now I use Print again to display ” : “, again no EOL.
Print(" : ")
And last I use PrintF to display formatted output. In this case I use %H to tell PrintF to display the hexadecimal value of the bVal variable. I also specified %E to tell it to output an EOL.
PrintF("%H%E",bVal)
Similar to the byte output above, this section does the same for a CARD (2 byte) value.
Print("Card : ") PrintCE(cVal) Print(" : ") PrintF("%H%E",cVal)
Similar again, this section does the same for an INT value.
Print("Int : ") PrintIE(iVal) Print(" : ") PrintF("%H%E",iVal)
Now I’ll use Print and PrintE to output a label for the line and the value of the character array sVal followed by an EOL.
Print("String: ") PrintE(sVal)
This section demonstrates PrintF’s power by displaying all of the values above on one line. %B is used to display a BYTE value. %U is used to display a CARD value. %I is used to display an INT value. %S is used to display a character array (string). And %E is use to output an EOL.
Print("Multi : ") PrintF("%B,%U,%I,%S%E",bVal,cVal,iVal,sVal)
Now that Print has been covered, there is another output command called Put. It also has a variant called PutE. However the PutE variant does not take any variables. PutE sole purpose is to output an EOL.
First I use PrintE to display a section header for the output.
PrintE("Put Examples")
I use Put to display the character value of bChar.
Print("Char : ") Put(bChar)
This just outputs a seperator.
Print(",")
Now I output the character again, and then use PutE to output an EOL.
Put(bChar) PutE()
End of the program main procedure.
RETURN
Complete Source
MODULE BYTE bVal=[255] CARD cVal=[1024] INT iVal=[32767] CHAR ARRAY sVal(30)="Inverse ATASCII" CHAR bChar=[65] PROC Main() PrintE("Print Examples") Print("Byte : ") PrintBE(bVal) Print(" : ") PrintF("%H%E",bVal) Print("Card : ") PrintCE(cVal) Print(" : ") PrintF("%H%E",cVal) Print("Int : ") PrintIE(iVal) Print(" : ") PrintF("%H%E",iVal) Print("String: ") PrintE(sVal) Print("Multi : ") PrintF("%B,%U,%I,%S%E",bVal,cVal,iVal,sVal) PrintE("Put Examples") Print("Char : ") Put(bChar) Print(",") Put(bChar) PutE() RETURN
Results
Next I’ll look at Input.
Pingback: Action! Input | Unfinished Bitness