Functions are the commands in Small Basic that
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.
Article tags
Related articles
Content Recommendation
Q.Why is Windows Backup skipping files?
Q.Why do my scanned documents display gibberish?
Q.How can I convert MTS files to edit in Windows Movie...
Updating your subscription status