Download presentation
Presentation is loading. Please wait.
Published byBethany West Modified over 9 years ago
1
CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)
2
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.
3
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.
4
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....
5
Properties What are properties? Properties are the variables or the constants that the object has.
6
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.
7
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.
8
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!
9
Let’s Take a Practical Example.... What are some properties of my daughter Lauren: Hair color Age She has two eyes
10
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
11
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.
12
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.
13
Go to smallbasic.com and click on Reference Documentation...
14
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)
15
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()?
16
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.
17
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.
19
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. reckstei@gmail.com
20
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. reckstei@gmail.com
21
Next Time.... We’re going to learn about flow control!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.