Simple clear advice in plain English

Small Basic Guide: 3. Making things happen with functions

Functions are the commands in Small Basic that

Loading the player ...
Functions are the part of a program that do things

If variables are the what, functions are the how. They are the actions of the program and can be very simple or very complicated. If you're wondering if they're like functions in Excel, you'd be exactly right. They're also referred to as methods.

Read more: Programming articles | Small Basic articles

Functions are identified by brackets after the name and just like Excel, there is normally some extra information inside the brackets. Writeline, used in previous videos to display the variables, is a function. Notice that the specific commands inside the brackets may differ such as the direct text to print or the variable.

You'll have also noticed that we don't use WriteLine on it's own but that there is some text that proceeds it, in this case TextWindow. TextWindow is an object.

An object is a collection of variables and functions that work together for a particular purpose.

You don't need a complete understanding of objects to use Small Basic but they help make sense of some of the commands and will be very useful if you move on to more capable programming languages. We've already used an Object and one of its functions. TextWindow is an Object and WriteLine() is the function. When using an Objects function or variable, write the name of the Object and then the function or variable, separated by a full stop. This example shows how you can get information about an object and change it.

colour = TextWindow.BackgroundColor
TextWindow.WriteLine(colour)
TextWindow.BackgroundColor = "white"
colour = TextWindow.BackgroundColor
TextWindow.WriteLine(colour)

The first line creates a variable called colour and sets it to the current background colour of the TextWindow object. The second line prints the colour using the WriteLine function. The third line changes the colour. The final two lines replace the contents of the colour variable with the new colour and display it on screen.

Reader Comments

   

Add your comment

Please keep comments constructive and free from abuse of any kind and swearing. If you wish to link to a product or service online, please do so in such a way that makes it clear that it is not spam. If you are connected to any such product you should make that clear.

We may use your comments in the magazine. We may edit your comments for clarity or to remove unacceptable material. We will attribute your comments but not share your email address.

We request your email address and record your Internet Address (IP address) in order to block spam from our site. We will never share this information without your permission.

All comments are reviewed by the Computeractive Team before being published. Please bear with the slight delay this causes, you don't need to post more than once.

Click here to read our Privacy Policy

Click here to read our site Terms & Conditions

Related articles

using the getItemCount property for a loop

Small Basic Guide: 4. Making decisions and looping

Seemingly long and repetitive tasks can be very simple with the If and For commands

small-basic-variables

Small Basic Guide: 2. Storing information in variables

We look at how to store and work with information in Small Basic

small-basic-hello-world

Small Basic Guide: 1. Introduction and first program

We introduce Small Basic, a great programming language for beginners

Content Recommendation

Question & Answer

Q.Why is Windows Backup skipping files?

> Read the answer

Q.Why do my scanned documents display gibberish?

> Read the answer

Q.How can I convert MTS files to edit in Windows Movie...

> Read the answer

Best deals on the web

img

Samsung NP350E7C-A04UK

£349.99- Buy it now

img

Toshiba Satellite C850D-11Q (PSCC2E-00R00JEN)

£279.97- Buy it now

img

Lenovo G580 (MAANJUK)

£379.99- Buy it now

Updating your subscription status Loading

Most popular articles

No matching document

Poll

Do you have Windows 8?

Jargon Buster

Computing terms explained in plain English

VGA

Video Graphics Array. Standard socket for connecting a monitor to a computer.

Great shopping deals from Computeractive

Information currently unavailable