Programming With Spreadsheets - Part 1

Published by at

Get your phone under control with the first part of our guide to Spreadsheet Programming.

What Is Programming?

So you're carrying around a computer in your pocket. Okay, people call them smartphones, communicators, PDA's or one of a million other names to try and pigeon hole them. No matter what you call them, it's a computer with a peripheral that allows you to take to other computers. Which means, like any computer, it's possible to write programs it.

Symbian OS has a large number of language choices, from C++ and Java, to OPL and Python (in some cases), along with AppForge's Visual Basic and scripting languages such as Simkin. But there is another way. A way which, while not as stylish and slick as some of the above, will still let you make use of the computing power available to you.

Here's a simple question, what is a computer program? Well, it's making your computer (smartphone / communicator / PDA / etc) do something for you. In the case of a complicated program like Opera, it's doing rather a lot of things at once: talking to other computers, laying out information, scaling pictures and images and working out a good layout of all the elements. Because of the complexity of the programming involved, the C++ language is the best choice. But the program it's doing something you want it to do.

Let's look at a program called Convert, that comes bundled with many Series 60 devices. In this application, you give your computer a number, it does a calculation and displays a result. How many practical computer programs are based around this principle of taking in some information, processing it, and displaying a result?

Now think about how you could use this idea in real life,. We've seen one, the units convertor, but what other uses are there? How about working out sales tax on items? Or checking your wages slip when you get paid? Tracking expenses and bank accounts? Computers are supremely good at crunching through numbers.

But how do you get to a point where you can work purely with these numbers and ignore all these big scary words like SDK, API, C++, DLL, MIDP, JIT, RAD, IDE, CPP and my personal nightmare, OOP? Welcome to the world of spreadsheets.

Spreadsheets as a Programming Language

Let's make this clear right now, these articles aren't aimed at programmers. Everything you see in this series of articles is easily replicated in the big languages. I'm aiming these articles at Power Users who don't program their phones and want to do more. Over the next three articles, we'll start off by talking about how a spreadsheet works, and prgramming a sales tax calculator. Next week we'll look at doing larger spreadsheets on your PC and moving them to your phone. Finally, we'll do a spreadsheet that allows you to track your bank account, just like a full blown financial application.

I want you to think about your phone as a true computer. Something you can control. Yes the majority of you are more than happy to grab programs by other people, but there always comes a point when you think 'I wish my phone could do that.' Hopefully, I can show you that you can program your phone. It's not something reserved for people who spend years learning languages, or take months of study in the evenings to be able to do it. Programming is something open to everyone.

Where To Get A Spreadsheet

Of course to program in spreadsheets, you'll need a spreadsheet application on your phone. Some phones have them built in, some will need you to download third party software and some (such as the P910) come bundled with the third party software you need.

Nokia Communicators

Luckily, the 9200's and the Series 80 powered follow ups both have a spreadsheet program (Sheet) built in.

Series 60 and UIQ

You're going to need to purchase a third party solution here, so there is going to be some initial outlay. We'd recommend Quickoffice (downloadable from http://www.quickoffice.com/). It's the nicest spreadsheet program out there, and you get a trial period before you have to buy it. The P910 comes with Quickoffice already bundled.

The Basics Of A Spreadsheet

So what exactly makes up a spreadsheet? Well, let's create a new spreadsheet inside your application. What you'll see will look something like this...

A Blank Spreadsheet

Cells

The first thing you can see is a grid of squares. Along the top and left edges you can see reference numbers and letters. These let you give each cell a unique reference of a letter and number combination. For example, the cell at the very top left is in column 'A' and row '1' so it is cell 'A1.' The cell below it is called 'A2' and the cell to the right of it is called 'B1'

Text Strings

The beauty of cells, is that you can put things in them. The simplest thing to put in them is text. Let's put some text in cell 'A1.' It's traditional for programming lanaguges to start with a 'Hello World' application where the computer displays the text 'Hello World' on the screen. Highlight the cell you want to place the text in, and then, depending on which application you have, let's enter the text.

  • Communicator (Built In)
    Move the cursor to the cell you want to enter data, press enter, and start typing.
  • Series 60 (Quicksheet)
    Move the cursor to the cell, and select edit. Type in the text using T9 or regular key taps. When finished, press in the cursor/stick again to accept the text.
  • UIQ (Quicksheet)
    Tap the cell where you want to enter data. The cursor will move to that cell. Now tap in the text area at the bottom of the screen (to the left of the tick and cross). You can now enter text normally. When finished, tap the tick.

Numbers

Numbers are entered in exacty the same way as text (see above).

Formulas

The key to a spreadsheet is using the numbers you've entered in one cell, and crunching them to do something else. When you enter a formula in a cell, you signify this by making the first character the '=' sign. Now your spreadsheet knows that rather than show the contents of the cell (as it does with a text string or a number), it shows the result of the formula.

Open a blank spreadsheet and enter the number 5 in cell A1. Now move to cell B1, and enter the formula '=A1'. Rather than seeing '=A1' in the cell, you can see the number '5.' Cell B1 is now a simple formula that says 'this cell should show the contents of cell A1. '

Let's edit the formula now, by doing the same procedure you used to enter the formula. You'll see that while the contents of the cell in the spreadsheet show the result, the edit box still shows the formula. Edit the formula to read '=A1+4' and you should see the on screen result of '9'

Of course, we're not restricted to referencing one cell per formula. So let's edit our formula in B1 again to read '=A1+A2' You'll see the result is still '5', because we haven't put any information in cell A2. Let's put the number '4' in there.

Notice that once you entered the number and finished in the edit box, the formula in cell B1 re-calculates itself immediately to reflect the new numbers in the spreadsheet. This is one of the keys to spreadsheets. No matter how complicated a spreadsheet, no matter how complicated a spreadsheet you have, each time you make a change, it is instantly reflected through all the formulas in a spreadsheet.

Our First Spreadsheet

Time to do something practical. Obviously spreadsheets are never going to be good for any games programming, but if you are involved with numbers in any sense, you should be able to find a use for a spreadsheet. The following spreadsheet takes in a price, and then calculates what that cost will be if you add or remove the sales tax (VAT) to the price.

A Blank Spreadsheet

Here's the completed spreadsheet on UIQ Quicksheet. There are two formula (in cells A4 and C4), that will use the sales tax rate in cell A7. Now, sales takes are normally given as a percentage, so you will need to do a bit of crucnhing yourself. 1.175 would be the number used for a sales tax of 17.5% (which is the rate in the UK).

Cell C4 contains the formula that will add the sales tax to the price you enter in cell B4. This formula is '=B4*A7'. Cell A4 subtracts the sales tax, using the formula '=B4/A7'.

You'll also note I've added a bit of colour in the formatting of the cells so when I come to use the sheet it's easy for me to see where I want to enter my price, and where the results are. You can do this to your spreadsheet in the following way.

  • Communicators (Build in Sheet)
    Highlight the cell(s) to edit, call up the menu and select the menu pane Format. The very bottom has the option Decorate, where you can select Background Colour.
  • Series 60 (Quicksheet)
    Go in to edit the cell, and call up the menu with the left hand soft key. Scroll down to the 'colour' menu option, and select cell background to change the colour.
  • UIQ (Quicksheet)
    Highlight the cell you want to edit. Press the third button in from the left on the bottom toolbar (the pencil over a line), and you can select the background colour.

 


 

That's it for this article. In part two, we'll look at some more spreadsheet techniques, and how to use a PC based spreadshet to make it easier to code larger sheets.