210 likes | 339 Views
CRE Programming Club Class 3. (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi). Point of Execution. This tells the exact point where the program is executing.
E N D
CRE Programming ClubClass 3 • (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)
Point of Execution • This tells the exact point where the program is executing. • A program will execute line by line. When it finishes one line (a statement), it moves onto the next. And the next. And the next. • And it keeps going, unless you tell it to go somewhere else in the program. So if I tell it later that A = 21, then 20 gets thrown away, and A now equals 21.
No Confusion • So, the important thing to remember here is: a program won’t do what it’s told to do UNTIL IT GETS to that line, and when it gets done executing that line, THE COMPUTER HAS DONE IT.
Let’s Learn About Objects • In the world of programming, objects are very important. In fact, about 25 years ago, they changed programming forever. What’s an object? Well, its easier to explain what an object contains....
Properties • What are properties? Properties are the variables or the constants that the object has.
Operations • Operations are things that the object can do, usually with the help of the properties. You can tell an operation as it is always followed by parenthesis.
Events • Events are things that happen outside our program that it may want to be aware of, such as the mouse moving or clicking, or a key being pressed on the keyboard. You may need to “handle” them.
What’s the Difference Between Operations and Events? • Operations are something we make happen. • Events are something that something else (outside the program) makes happen...and we want to know about it!
Let’s Take a Practical Example.... • What are some properties of my daughter Lauren: • Hair color • Age • She has two eyes
What Are Some Operations? • Jump up and down the number of times of your age • Brush your hair • Tell us how many eyes you have
What Are Some Events? • She is sick • She is hurt on the playground • A boy kissed Lauren (I really want to know this!) • Remember that events are not operations! Operations are things that our program makes happen. Events happen outside the program, and the program needs to know about them.
Know the Docs • Look online at TextWindow documentation (Reference Documention on smallbasic.com) • Also, did you notice that when you were typing in TextWindow, the Intellisense also tried to guess what you wanted. If you choose TextWindow, it will display all the properties, events, and operations that an object has. • So, TextWindow has properties like “Title”. It has operations like “WriteText” and “Read”. It doesn’t have events.
Go to smallbasic.com and click on Reference Documentation...
Accessing Objects • We get ahold of properties, events, and operations by writing the name of the object, followed by a dot, followed by the name of the property, event, or operation. So, for example. • Math.PI (constant) • TextWindow.Title = “My Program” (variable) • TextWindow.writeLine(...) (operation) • TextWindow.readLine() (operation) • TextWindow.clear() (operation)
Operations • With operations, we can give information to it by putting it inside parenthesis. In fact, if you look at the object documentation, many operations expect one or more things to be passed to it. • On the first day, what did we pass into TextWindow.writeLine()?
Operations • Some operations will also return something. We can get ahold of it by assigning the return value to a variable. It looks something like this: • shapeName = GraphicsWindow.addEllipse(5,5) • You can pass in a more than one thing to an operation, but operations in Small Basic will only return one thing.
Using the Small Basic Classes • Many programs use some of the Math functions, as well as some of the Clock functions. • Clock.getMonth() • Clock.getDay() • Clock.getCurrentTimeMillis() • What is the last one good for? We can use it as sort of a stopwatch, to figure out how long something in our program is taking.
Import VJC505 • This is your second homework assignment. • Complete the first six variables by obtaining their values from the Clock object. • Use the TextWindow.WriteLine() command to print out the results. • Questions? Send me an email at reckstei@gmail.com.
Import MCL293 • This is your second homework assignment. • This program uses the GraphicsWindow object to create a graphics window to draw on. It sizes it, draws “Hello There”, and makes it visible. • Use other operations and properties in GraphicsWindow to make this more interesting. I don’t care how. • Questions? Send me an email at reckstei@gmail.com.
Next Time.... • We’re going to learn about flow control!