19.04.2017 Views

Learn to Program with Small Basic

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Helping Hands: IntelliSense and Syntax Coloring<br />

If you’re following along and typing in <strong>Small</strong> <strong>Basic</strong>, you’ve seen how it analyzes<br />

what you type, even before you finish the word. <strong>Small</strong> <strong>Basic</strong> offers a list<br />

of suggestions that could help you complete what you’re typing. You can scroll<br />

through this list by pressing the up and down arrows on your keyboard. Press<br />

enter or double-click your selection <strong>to</strong> insert the highlighted text in<strong>to</strong> your<br />

code. This technology is called intelligent sense or IntelliSense for short. Use it <strong>to</strong><br />

speed up your typing time and reduce your syntax errors.<br />

Tip<br />

You can make IntelliSense transparent by just holding down the ctrl key <strong>to</strong> see your<br />

code underneath it.<br />

You might have also noticed that the <strong>Small</strong> <strong>Basic</strong> Edi<strong>to</strong>r used different<br />

colors for some words in the program. This feature is called syntax coloring.<br />

Keywords, which are reserved words <strong>with</strong> special meanings <strong>to</strong> <strong>Small</strong> <strong>Basic</strong>, are<br />

shown in blue-purple. Strings, which are sequences of characters enclosed in<br />

quotes, are orange, and so are numbers. Method names are dark red, object<br />

names are blue-green, and so on. Syntax coloring helps you distinguish the<br />

different parts of the code and makes your program easier <strong>to</strong> read. You’ll<br />

learn more about these parts of code later in the book.<br />

Drawing <strong>with</strong> <strong>Small</strong> <strong>Basic</strong><br />

The TextWindow object we used earlier works well for applications that don’t<br />

have a graphical user interface (GUI), which is a user interface that contains<br />

but<strong>to</strong>ns, text boxes, and images, like Microsoft Word or Angry Birds (or<br />

Angry Words). For example, you can use TextWindow <strong>to</strong> write applications<br />

that perform math problems or that process data, where the input and output<br />

use only characters (like text). This is called a text-based user interface.<br />

If you want <strong>to</strong> create an application <strong>with</strong> a GUI (pronounced gooey, like a<br />

candy bar), complete <strong>with</strong> but<strong>to</strong>ns and images, you can use the <strong>Small</strong> <strong>Basic</strong><br />

library’s GraphicsWindow object. Using GraphicsWindow, you can create applications<br />

that show but<strong>to</strong>ns, images, and more for your users <strong>to</strong> interact <strong>with</strong>.<br />

Let’s try it out!<br />

Enter the program in Listing 1-2 in<strong>to</strong> the Edi<strong>to</strong>r, and then click Run in<br />

the Toolbar.<br />

1 ' Graphic.sb<br />

2 GraphicsWindow.DrawText(100, 50, "Greetings, Planet!")<br />

Listing 1-2: Your first graphical program<br />

Introducing <strong>Small</strong> <strong>Basic</strong> 9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!