Windows
Variable Conversion
Loops in Errortrapping
Windows
Lesson Goal
Don’t worry about making this now, we’ll build towards this for the end of the lesson.
Variable Types Review
Type Incompatibility
Variable Types Summary
Type | Values | Examples |
int | Integers, whole numbers | 5, -2000, 127 |
real | Numbers with decimals | 7.1, 83.0, -157.6 |
boolean | True or False | true, false |
string | Text (a string of characters) | “Apple”, “i!^”, “”, “0.9” |
char | A single character | ‘A’, ‘=’, ‘3’, ‘p’ |
Variable Conversion
Command | Effect | Usage |
strreal(real) | Converts string to real | Taking input |
strint(int) | Converts string to int | Taking input |
realstr(real, n) | Converts real to string, with n reserved spaces | Text formatting |
intstr(int) | Converts int to string | Text formatting |
Example
Safe Conversion
Error-Trapping Input
Error-Trapping Example
Pauses and Delays
Two methods are pausing a program
var ch : char
ch := getchar
delay(1000)
Loops
Loop Example
Common Uses for Loops
Practice
Ask the user for an integer, and output its value doubled. If the input isn’t an int, ask for input again until it’s valid.
Solution
Windows
Creating Windows
Practice
Create a window with:
Solution
Window Commands
Command | Purpose |
Window.Show(winID) | Shows a window, user can’t with it |
Window.Hide(winID) | Hides a window, user can’t interact with it |
Window.Close(winID) | Closes a window, program can’t interact with it anymore |
Window.Select(winID) | Selects the current window |
Program States
Switching States
There are 2 ways to handle windows:
States Example
STATE: SLEEPING
STATE: EATING
EVENT: GIVEN FOOD
EVENT: DONE EATING
Windows Example
(Window 1)
I’M SLEEPY!
(Window 2)
I’M HUNGRY!
1
2
Code Example
Create windows
Event 1 hides win1, shows and selects win2
Event 2 hides win1, shows and selects win2
Events are triggered by user input in a loop
Main Challenge
Main Challenge Plan
(Input)
ENTER
AN INTEGER
(Output)
THE INTEGER
MULTIPLIED BY 4 IS...
(Error-Trap)
YOUR INPUT
WAS INVALID
2
3
1
Solution