<< Click to Display Table of Contents >> Navigation: Concordance Programming Fundamentals > Using Common CPL Functions > User Interface |
You can use the following user interface functions (puts, messagseBox, and getkey) to display text to the user as well as to get user input.
Puts() is one of the most convenient ways of displaying text to the user. The following code displays the syntax for puts.
puts(int row, column; text string); |
The first two parameters, row and column, specify the row and column number where you want to place your text. Imagine the CPL screen as a piece of graph paper. Depending on how large you make the window, the more squares on the graph paper you will see. Each square on the paper represents a place where you can place a character such as ‘A’ or ‘d’. The top left corner of the screen is row 0 column 0. As you move to the right of the screen, the column number increases. As you move down the screen, the row number increases. The third parameter, string, is the text you want to display.
|
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
0 |
|
|
|
|
|
|
|
|
|
|
1 |
|
|
H |
e |
l |
l |
o |
|
|
|
2 |
|
|
|
|
W |
o |
r |
l |
d |
|
3 |
|
|
|
|
|
|
|
|
|
|
The text above would have been placed on the CPL screen using the following code:
puts(1, 2, "Hello"); puts(2, 4, "World"); |
You are probably familiar already with Windows message boxes. CPL has a built-in function to display your own. The messageBox function has the following format:
int messageBox(text szText, szTitle; int style); |
The first parameter, szText, is the text of the message box you wan to display. The second parameter, szTitle, is the title of the message box. The third parameter, style, can be several values. For more information on style, see About the Concordance Programming Language Reference.
This message box was produced using the following line:
messageBox("This is a great class!", "CPL", MB_OK); |
Getkey pauses the program and waits for the user to press a key. The syntax of getkey is as follows:
char getkey(); |
Getkey does not take any parameters, but instead pauses the script until the user presses a key. Then, the function returns the key that the user pressed.
For example, suppose you want to write a program that accepts the letter ‘A’ or ‘B’ from the user. Here’s how you would write it:
input() { int value;
value = 0; puts(5,10, "Enter code:"); while(value == 0) { switch(getkey()) { case 'A': case 'a': value = 1; break; case 'B': case 'b': value = 2; break; default: break; } }
return(value); } |