In this post I explore the Action! input routines.
Just as there are many ways to output to the screen in Action!, there are also many ways to input in Action! There are several flavors of the Input procedure. There are versions specific to each data types.
Input Variants
- InputB – Inputs byte value. Range is 0 to 255. Returns the input value.
- InputC – Inputs card value. Range is 0 to 65536. Returns the input value.
- InputI – Intputs integer value. Range is -32768 to 32767. Returns the input value.
- InputS – Inputs string (char array) value. String pointer is passed to function. String is modified directly.
One thing I left out in both Input and Print are the variants for device access. I’ll cover those later when I start exploring file I/O.
Demonstration
Here is a short program that demonstrates each variant, with a breakdown. The complete un-interrupted source will be presented at the end. This program is based on the print program presented in the previous post “Action! Print and Put“. I will only breakdown the input parts in this post.
Here I declare a variable of each type and initialize their values, unlike the print program this initializes all variables to zero and null for the string.
BYTE bVal=[0] CARD cVal=[0] INT iVal=[0] CHAR ARRAY sVal(30)
This is the start of the main procedure. Every Action! program must have at least one procedure. This is the same as the print program, listed here so you can see where changes are occurring.
PROC Main()
This prints a section header on the display with an EOL.
PrintE("Input Examples")
I use Print to display the input prompt showing the range of allowed values. No EOL is output since I don’t want the cursor returned to the next line yet. This is for the BYTE value.
Print("Byte (0 to 255)?") bVal=InputB()
Again I use Print to display the input prompt showing the range of allowed values. No EOL is output since I don’t want the cursor returned to the next line yet. This is for the CARD value. For display purposes the range starts at 256, but in reality it’s 0.
Print("Card (256 to 65535)?") cVal=InputC()
Again I use Print to display the input prompt showing the range of allowed values. No EOL is output since I don’t want the cursor returned to the next line yet. This is for the INT value.
Print("Int (-32768 to 32767)?") iVal=InputI()
And last I use Print to display the string input prompt showing the length allowed. An EOL is output since I want the cursor returned to the next. This is for the STRING (CHAR ARRAY) value. Notice the call is slightly different. The value is not returned from the input function, the variable is modified directly (passed as a pointer).
Print("String (30 characters)?") InputS(sVal)
Thats all for the changes, barring a PutE() before the Print Examples.
Complete Source
MODULE BYTE bVal=[255] CARD cVal=[1024] INT iVal=[32767] CHAR ARRAY sVal(30) PROC Main() PrintE("Input Examples") Print("Byte (0 to 255)?") bVal=InputB() Print("Card (256 to 65535)?") cVal=InputC() Print("Int (-32768 to 32767)?") iVal=InputI() PrintE("String (30 chars)?") InputS(sVal) PutE() 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) RETURN
Results