80-Bus News


September–October 1983, Volume 2, Issue 5

Page 61 of 67

More about databases

by D.R. Hunt


Having read the title and having been put off by ‘databases’, a little diversion for starters. Time and again newcomers to BASIC are stumped by the need to look up things in databases. The first problem is that they don’t know what a database is, and secondly, when they find out, they get frightened of it. If this sounds like you, read on, otherwise, skip to the harder bit.

I don’t know why, but when beginning to learn programming in BASIC, most people prefer to leave arrays very strictly alone. I know I was like that when first confronted with an array when I actually laid hands on a Nascom BASIC (was it really all those years ago?). I even went to considerable lengths to program around them. Yet in truth, an array variable is just like any other variable except a bit more versatile. The main problem lies in visualising arrays. I explain to people thus:

‘A single dimensional array is easy to picture. Imagine a single row of pidgeon holes numbered 0 to n, where n is as big a number as the number of pidgeon holes required. Anyway, there are these pidgeon holes, and this row is called P (for pidgeon), so P0 is the first pidgeon hole, P1 is the second pidgeon hole, up to Pn where n is the highest numbered pidgeon hole. Got that? Ok. Now lets indulge in a bit of lateral thinking (‘cos it’s row, remember), well, lets call the whole row P, and refer to the numbers of the pidgeon holes by the same numbers as before, but put the numbers in brackets to indicate that the numbers refer to the individual pidgeon holes while the ‘P’ refers to the row. So each pidgeon hole is now called P(0) through to P(n). Ok. Now that’s the easy bit. Now let’s add another row of pidgeon holes beneath the existing row P. We can’t call this P, ‘cos the other one is called P, so by stretching the imagination we’ll call this one Q. Now notice, Q(0) is directly beneath P(0), and Q(n) is directly beneath P(n). We now have two ‘one dimensional’ arrays. We can add as many one dimensional arrays as we need for any job. The important thing is the pidgeon hole (n) in one array is always directly related to pidgeon hole (n) in any other one dimensional array. Now there are such things as two dimensional arrays, best imagined as areas of squared wall paper, or three dimensional arrays, looking like lots of cubes arranged into box shapes. After three dimensions, my imagination gives up, but having grasped three dimensional arrays, n dimensional arrays aren’t too difficult to use, even if you can’t imagine then.’

Well, back to the simple database lookup bit, lets go for a telephone directory. All very simple, we use two one-dimensional arrays, one containing the names to be looked up and one containing the appropriate telephone number. The only pre-requisite for this sort of program is the necessity of being able to save and reload string arrays. Now watch out for this one, Nascom 8K BASIC has severe problems in this area as it can’t save and reload string arrays. A number of ingenious solutions have been published in early editions of INMC80 so it’s back into the archives if you want to use this program with Nascom BASIC.

Page 61 of 67