My goal to learn something new every day
With not as much work to do this weekend, I’ve finally had a bit of time to get round to some hobbies. I’ve been interested in computer coding for quite a while, but it’s only in the last year or so, that I’ve started learning more about programming (as opposed to scripting, which is more about learning a few of the basics and then just adapting them). Recently I’ve been reading more about VBA, which is a programming language that is built into other applications, such as Microsoft Office programs. I’ve been using it for about 3 years, and created a PowerPoint scoreboard a while back, which is easily the most popular page on my other blog.
While the scoreboard worked, it perhaps wasn’t the most beautiful of designs (code wise). At the end of last year, I got about 25% of the way through Harvard’s introduction to computer science course (CS50x) on edX before work began to pick up, and I didn’t have time to finish it. Fortunately, the course runs the entire year, and resets every January, so I’m hoping to get back to it some time later this year, but I digress.
From the content that I did manage to cover on CS50x last year, one thing that was constantly re-iterated was the desire for elegant code as opposed to code that just works. During a lot of my previous efforts with VBA, I’ve done things the ‘long way’ mainly because I didn’t know how to do things ‘properly’. So this weekend, I finally had the chance to catch up on some reading with VBA, and put together a basic game in PowerPoint:
Anyone from the UK will certainly be aware of the popular daytime TV game show Countdown. If you’re not from the UK, it may be unfamiliar, although I think some countries do have similar versions, such as Australia, which had a game called Letters and Numbers. You can read more about it here.
So far today, I’ve just built a very basic version of the Numbers Game, which you can read more about on the Wikipedia page (link above). The PowerPoint is very basic in terms of aesthetics at the moment, but should work as intended. I’m hoping to get around to finishing the whole thing with a letters round over the week.
You can download a version of the game so far here. Because it uses additional code, Microsoft’s security settings might try to block some of the content. If you’re working in Office 2007 or newer, you should see a yellow banner at the top of the page asking you to enable content. You’ll need to click this to get the file to work. If you don’t see the banner, you will need to adjust the Trust Settings in your version of Office. To do this, click on FILE, then OPTIONS. Select TRUST CENTER from the menu on the left, and then choose TRUST CENTER SETTINGS. There will be four options, and I suggest choosing Disable Macros with Notifications. This means that Office will always let you choose whether to enable code (which can be potentially harmful to your computer), before you open up a file. You’ll notice that the file is saved as a .pptm, and not a .pptx file, which is probably more familiar. This just means that it contains additional code. It won’t work on computers with Office 2003 or older versions, and I have no idea whether it will work on Macs or not, because I’ve never used an Apple computer before.
While I haven’t focussed on the technical aspects of what I learned how to do today, for anyone interested, I figured out how to use Arrays, Do… Loop while loops, For… Next loops and Select Case statements. The code is left unlocked in the file for anyone who wants to read it themselves.