Programming HP Calculators/Commands/Prompt Commands
BEEP[edit | edit source]
- Uses the calculator's piezoelectric beeper to beep at a frequency of <freq> Hz for <time> seconds.
INT(RANDOM*9+1)?R: MSGBOX "Guess the number between 1 and 10." WHILE A?R REPEAT PROMPT A: IF A==R THEN BEEP 400;.2: BEEP 600;.5: MSGBOX "You win!": STOP: ELSE BEEP 600;.2: BEEP 400;.5: IF A>R THEN MSGBOX "Lower..": ELSE MSGBOX "Higher..": ELSE END: ELSE END:END:
This program generates a random number from 1 to 10, and prompts the user for a guess. If the user guesses correctly, the calculator beeps twice with rising pitch (typical "correct" sound). Otherwise, it beeps twice with lowering pitch (typical "wrong" sound), and tells the user if the answer is higher or lower than what they specified.
CHOOSE[edit | edit source]
CHOOSE <variable>; "<title-name>"; "<option-1>"; "<option-2>"; ... "<last-option>":
- Allows the user to select from a set of options given on the screen.
- After two ;s, CHOOSE starts allocating spaces on the on-screen menu and assigning values to those spaces. Therefore, in the syntax example, <option-1> would have a value of 1 - if it were selected, <variable> would be set to 1.
- This option is best used in conjunction with CASE to define the effect of each option.
- CHOOSE starts with the current value of <variable> as the item selected. Therefore, it will be impossible to use the menu should the variable have a value that is not a positive integer, or is greater than the number of options.
- A simple workaround for the following is always inserting 1?<variable> at the start of the CHOOSE command, to ensure that the first option is selected by default.
DISP[edit | edit source]
- Displays <text> on line number <line> (1 to 7).
- Although there is room for 8 lines after an ERASE, setting <line> as less than 1, non-integer, or more than 7 will result in the text simply not printing (no error message).
- DISPXY is able to handle printing on the "8th line", should you require more room.
- DISP erases the contents of the entire line that it is about to print on, regardless of whether or not pixels have already been drawn in that area. Therefore, you should always use DISP first, should you intend to draw over it. DISPXY corrects this problem to a degree, although use of it still results in some whitespace being forced over your drawing.
- This can be used to your advantage should you wish to blank out a certain line of text, simply use DISP <line>;" ":. This can be advantageous as it will obfuscate your code (if you want to limit the alterations people make to your code), and because it is much faster than any other method (although it allows the least control).
ERASE:DISP 1;"Hello World!": FREEZE:
Displays the ubiquitous "Hello World" on the first line on the screen, after erasing the screen, and freezes the program at the end so that the user has time to read the message.
1?A:1?B:ERASE: FOR X=1 TO 500; A+B?C:B?A:C?B: B/A?P: DISP 1;B":"A: DISP 2;P:
Advanced: Approximates phi using the ratio between increasing Fibonacci numbers. The ability of DISP to erase the line before displaying its payload creates an interesting-looking "reiterative" effect.
DISPTIME[edit | edit source]
- Displays the date and time in a message box.
- The time is stored in the TIME and DATE real variables.
- TIME syntax: hh.mmss (with hh in 24-hour time). For example, 2:30PM is 14.3000. Since the variable is an integer, the 0s at the end actually go on for 13 characters; this is because the TIME variable actually stores fractions of seconds, too. (Thus you could set 1PM as just 13, or 12:05:30.136 as 12.0530136.)
- DATE syntax: mm.ddyyyy. For example, 21st September, 2005 is 9.212005.
This program is called "TimeUtils".
1?M:CHOOSE M; "Display time"; "Set time": CASE IF M==1 THEN DISPTIME:STOP:END IF M==2 THEN MSGBOX "Hour? (24h time)": PROMPT H: MSGBOX "Minute?": PROMPT M: H+M/100?TIME: MSGBOX "Set. Date?": PROMPT D: MSGBOX "Month?": PROMPT M: MSGBOX "Year?": PROMPT Y: D+M/100+Y/1000?DATE: MSGBOX "Set.":RUN "TimeUtils":END END:
This program is a multi-function application that allows you to both display and edit (correct) the current time. Most of it should be self-explanatory, given the information about the DATE and TIME variables in Details.
EDITMAT[edit | edit source]
FREEZE[edit | edit source]
- Pauses the running of the program, waiting for input from a key.
- Best used after using drawing commands, or else the drawings will disappear from the screen straight away.
- For the readers who know more advanced programming languages, it is the same as GETKEY, but it does not return a value to the calculator (ie. cannot detect which key was pressed).
GETKEY[edit | edit source]
INPUT[edit | edit source]
MSGBOX[edit | edit source]
- The simplest way of displaying a message on screen, requiring only the text to be displayed; however, this is its weakness - it offers almost no control.
- Automatically incorporates a FREEZE, that is, you need to press a key to get out of the MSGBOX.
PROMPT A: MSGBOX "You entered "A".":