Sei sulla pagina 1di 14

LESSON 3: THE TEXT WINDOW FIRST STEPS IN SMALL

BASIC
OBJECTIVES
To understand objects, properties and operations in Small Basic

To display and enter text in the Text window

To use variables in a program


OBJECTS
Objects are identified by the orange cube
They are a package of operations and properties that you can use
An example of an object is GraphicsWindow, TextWindow, Math and
Turtle
PROPERTIES
Properties are identified by the
colour palette
information stored by an object
Usually assigned by =
Example GraphicsWindow.Width = 800
OPERATIONS
Sometimes called methods
Accept an input in brackets
Example: Turtle.Move(50)
THE TEXT WINDOW
So far we have been working in the Graphics window
The Text window is used for entering and displaying text and
numbers
Try running the following program

TextWindow.Title="Using the Text window"


TextWindow.WriteLine("Hello there!")
TEXT WINDOW COMMANDS
What does the statement below do?

TextWindow.Title="Using the Text window"


Double-click the word TextWindow in your program and look at the
list of commands in the Help window
Well be using the Write, Writeline, Read and ReadNumber
commands
WRITING TEXT
TextWindow.Writeline("Hello") writes Hello and then goes to a new
line
TextWindow.WriteLine("") goes straight to the next line without writing
anything
TextWindow.Write("Hello, " + "Laura") writes Hello, Laura and stays
on the same line
Try out these statements with some text of your own
What happens when the program has run the last statement?
LETTING THE USER ENTER DATA
Now try the following program:
Textwindow.WriteLine("What's your name?")
Name = TextWindow.Read()
TextWindow.WriteLine("")
Textwindow.WriteLine("Hello, "+Name)
TextWindow.WriteLine("")

Spaces are ignored, unless . what?


READING TEXT AND NUMBERS
When data is input to the computer, it has to be stored somewhere
The programmer chooses a name for the location where the computer
stores the data
This is called a variable, because its contents will vary
You should choose a name that gives you a clue what is stored there
MEANINGFUL VARIABLE NAMES
Textwindow.WriteLine("What's your name? ")
Name = TextWindow.Read()

Think of variable names that would be suitable if the computer had


asked,
Whats your favourite food?
What street do you live on?
Whos your favourite singer?
What year were you born?
NAMING VARIABLES
The name must start with a letter
It can be any combination of letters, digits and underscores
It should not be a reserved word that is part of Small Basic like For,
Read, Writeline
CONCATENATING OUTPUT
Concatenating means joining up

Textwindow.WriteLine("Hello, "+ Name)

Here youve joined up the word Hello with the name entered by the
user
Now try Activity 1 on Worksheet 3
READING NUMBERS
If you want to read in a number that you are going to calculate with,
you should use

TextWindow.ReadNumber()

TextWindow.WriteLine("How old are you?")


Age=TextWindow.ReadNumber()
Age=Age+10
TextWindow.WriteLine("In ten years youll be "+ Age)

Potrebbero piacerti anche