21
CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

Embed Size (px)

Citation preview

Page 1: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

CRE Programming Club

Class 3

(Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

Page 2: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

Point of ExecutionThis 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.

Page 3: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

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.

Page 4: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

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....

Page 5: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

Properties

What are properties? Properties are the variables or the constants that the object has.

Page 6: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

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.

Page 7: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

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.

Page 8: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

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!

Page 9: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

Let’s Take a Practical Example....

What are some properties of my daughter Lauren:

Hair color

Age

She has two eyes

Page 10: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

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

Page 11: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

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.

Page 12: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

Know the DocsLook 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.

Page 13: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

Go to smallbasic.com

and click on Reference

Documentation...

Page 14: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

Accessing ObjectsWe 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)

Page 15: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

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()?

Page 16: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

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.

Page 17: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

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.

Page 18: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)
Page 19: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

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 [email protected].

Page 20: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

Import MCL293This 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 [email protected].

Page 21: CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)

Next Time....

We’re going to learn about flow control!