Real Logo
REALbasic Home
X
Thank you for trying this tutorial ... It is not associated with REAL Software.     powered by ... a desire to share
space


Introduction to REALbasic for the Mac


space
space space
space Contents
What You Should Know
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9

My RB Samples
space spacespace
space
space
space space
Lesson 8: Writing Code ...
by Thomas J. Cunningham

 
  space space

A Little Coding Baby ...
8. The Code Editor - continued ...

Our next coding gem is to duplicate our StaticText size. Close your Code Editor window for now and open your Window1 - window. Drag a StaticText class (the letter "A") in to your window. You should see the now familiar "Label:". The Properties Window indicates its' name as StaticText1 and its' Super as StaticText. With the Label: still highlighted, double click it. RB takes you to the Code Editor of our window, and to the statictext control handler.

editor

Six different Event Handlers are present for this class, courtesy of RB. We are going to use the Open event just like we did earlier to code for the window title.
Please note a few things before we start writing our code. StaticText is a Control of the window. The Events Handler is Bold. This is another visual interface clue that RB gives you. The Events handler is bold because it now contains code, the code we provided in the previous chapter. Another simple REALbasic Mac type user interface to help you keep things organized.

From Chapter Seven, our first task is to comment our code (remember ?).

    In the Open Event Of StaticText1

  • // I want to change the size of the text to 18 Window1.StaticText1.TextSize=18

We are going to simplify this code a bit in a moment, but let's be clear on the syntax here. We start out in a general, wide view of our house (Window1) and we refer to it by name. Next, what part of the house ? (the Statictext Class Instance) StaticText1 by name. What property of the text do you want to change ? (the TextSize). And finally, what size would you like ? (18).
How can we know what properties are available to be changed (or read) into the StaticText Class ? Command - 1 that's how, our trusty on-line reference. Look it up !

    A little Pop Quiz ....
  • Why can't we rewrite the above code like this ?
    // I want to change the size of the text to 18 MyFirstWindow.StaticText1.TextSize=18

If you copy this in to your open event of the statictext, you get an error message from RB:
"Unknown Identifier "MyFirstWindow".
Why? Isn't this the name of our window ? No, it is not. My First Window is the Title property of Window1 not its' name. If you missed this, perhaps you should go back to Chapter 7. How you refer to objects in RB is simply experience with the language.

At the risk of confusing you a little bit, I am going to introduce the use of the code word, ME.

// I want to change the size of the text to 18
Me.TextSize=18

This works exactly the same way as the first code above. Copy and paste it in to your project and see ! It makes sense if you think about it a minute or two. Me refers to the statictext1 class that's in window1, because that's where this code originates ! Don't get all hung up with this if it is confusing. I mention it only to solidify the fact that there are several ways to write code. Both sets of codes run the same and the first one I gave you is far easier to understand for beginning programmers to comprehend.

Not to belabor the point, but this nonsense code should make sense to you.
Earth.UnitedStates.Arizona.Phoenix.AlSmith.PhoneNumber=408.455.7824

And ... we're off in a cloud of bat doodoo to Chapter Nine.


Chapter 9

 


Your REALbasic (RB) Learning Library and Reminders

- An RB Rule
A few more hints and rules that RB uses. Some computer languages allow the programmer to write code on several different lines. With RB, you have to place all of your code for a particular operation or message on ONE line.

- Case Sensitive
Some computer languages insist that words be capitalized in some places and other rules regarding case. RB, thank goodness, does not care. This is a huge deal for beginners, so thank REAL for this coder friendly syntax ! For Example: RB sees all of these window property descriptions as the same: TItle, TITLe, titlE, etc.

- A Review
Just to see if you are paying attention up to this point. If I tell you that when you run this chapters exercise, that we are creating an Instance of the StaticText Class called StaticText1 in Window1 whose Title property is My First Project, ......... you are not completely freaked out by this vocabulary, are you ? You should not be completely. Most, if not all of this should be clear up to this point. If not, don't worry, we will be building more on these concepts !
.

____

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |   9 |


Find This Useful / Not ? Email Me : mauitom@maui.net

Copyright 2001,Thomas J. Cunningham