Sunday, 21 September 2008

Visual Basic

Visual Basic


Ex-colleague to rescue

I eventually decided, in the autumn of 1997, to try to contact a former colleague in Leeds to see whether he could help. Despite the fact that I'd quoted him as referee for that Dudley metropolitan borough council vacancy, we hadn't been in touch for about ten years, at which time I'd still been working. He was horrified to learn of my situation but was able to give me a personal computer (an ICL DRS M55 that ran on Windows 3.1) with Visual Basic and some other stuff on it. I practised a lot on that machine and gained my first real experience of object-oriented programming, which is a lot more modern than the COBOL programming that I'd traditionally done.

One side benefit of this newly acquired computer was that I could do my own word processing, so I no longer needed to pay specialist typing services. Apart from giving me something else to practise, this also saved me money.

Rewrite old routines

I began by writing various routines that I had written in C when I started learning that language in 1996. These included prime number manipulation and a game. I described them in detail in my page about C programming. Because I had written these programs before in other languages, they did not test my programming skills. Any difficulties that I encountered were entirely due to unfamiliarity with Visual Basic, enabling me to identify and solve any problems quickly. I also experimented with colour manipulation and many other aspects of object-oriented programming.

Add calendar

My first new routine was a calendar program, which displayed any month between 326 AD and 3999 AD. Calendar changes and likely changes determined the limits, although I catered for the 11 "missing" days in 1752. The calendar program, together with the other simple programs that I'd rewritten, gave me a sound knowledge of the fundamentals of Visual Basic, without really testing my programming skills.

Betting calculations

Despite being a huge Horse racing fan, I've never been a big gambler and when I do bet, it is almost always via single bets on individual horses. I very rarely bothered with multiple bets such as doubles, trebles and Yankees. Insofar as I experimented with them when I was younger, I realised that they were mostly a waste of good money, so I never even tried the multiple bets that bookmakers love, such as Canadian, Heinz and Union Jacks.

Nevertheless, I knew that herein lay an interesting programming challenge although the idea was simple enough. Name the type of bet, the unit stake and whether betting tax was payable, then name each of the horses, together with their starting prices and whether they won or lost. The program's job was to calculate the winning returns, deducting tax if required. Yes, we Brits still had betting tax in those days. Offshore bookmakers using the internet killed off the betting tax.

Oh yes, and if I had any doubts about the wisdom of placing a Union Jack bet, my program proved just what a mug's bet it really is. You might be lucky and get some money back with just three winners out of your nine horses, but you could be unlucky enough to pick six winners and lose the lot. If you must try this bet, you really need the horse in the central position to win to give yourself a fighting chance. It is part of four trebles. The four corner horses each contribute to three trebles, while the other four contribute to just two each.

The betting calculation project turned out to be much more complex than I originally anticipated, which pleased me because I needed something to force me to think hard. Although still not a commercial system, it used many of the techniques necessary in a commercial environment, such as moving from one screen template (form) to another, printing, string handling, graphics and multi-dimensional array handling. I used the printing option as an excuse to experiment with different font types and sizes, allowing the user to specify how the print should appear.

Flags

The betting calculation project introduced me to serious graphics for the first time, albeit by accident. Among other things, to do a really professional job, I needed to work out how to draw a Union Jack, to provide an appropriate background to the bet named after it. (And yes, I'm aware that it's more correctly called a Union Flag except when used at sea, but it is most commonly, if incorrectly, known as a Union Jack so I'll stick with that, since the bookmakers do.) I eventually worked out how to draw the Union Jack purely by programming (the normal way would be to use some kind of paint software) and realised that drawing flags would be a good way to learn about graphics.

I therefore created a program to display or print flags of various countries, together with any other flags that appeared interesting and programmable. Some flags are impossible to draw purely by programming as they include birds, animals or other features that don't fit standard shapes. The paint software doesn't interest me as I'm a programmer, not an artist. Despite the restrictions, there were plenty of flags that I could draw.

While developing the flag program, I was pleasantly surprised to learn that I could eventually draw some features, particularly stars, that initially seemed impossible. It took me a long time to work out how to program five-pointed stars, which are common in flags, but perseverance paid off. Eventually, I was able to draw a circle of stars with each star rotated so that the points are correctly positioned as in the real flag. The European Union flag is perhaps the most famous example of a flag with a circle of stars, but it's not the only one. The American Stars and Stripes is particularly interesting, especially when one looks back in time. Although the current flag has a fairly straightforward arrangement, there being too many stars now for fancy arrangements, there have been times in the past when the pattern was not so simple. Some of the old patterns included a circle of stars.

Like everything else I did on that computer, the flags program was a non-commercial application but many of the techniques used could be applied commercially. I had no particular interest in flags prior to writing this program, but I bought several books on the subject to provide me with pictures and other information, some of which I've reviewed on Amazon including The world encyclopedia of flags. See how the different aspects of my life interact?

Good training

By means of the above systems, I learned far more about Visual Basic than I could ever hope to do on a training course, although there are some aspects of the language that require a commercial environment in order to learn them effectively. I never did any file handling or database, because I didn't have the software to allow me to do them.

The fact that I'd been practising Visual Basic at home was almost certainly a factor in helping me back to work, even though there was no requirement for these specific skills in the job that I secured. I continued practising even after I started work, albeit intermittently, until the computer expired. Fortunately, I had kept security copies so maybe I can return to Visual Basic someday. However, any hopes that I once held of returning to commercial programming have all but disappeared, so it will probably be just a fun thing to play with during my retirement.

No comments: