Personal Computer News


Is My Spectrum A Bit Dim?

Categories: Letter

 
Author: David Scott
Published in Personal Computer News #065

Is My Spectrum A Bit Dim?

Q. I am writing a program on my 48K ZX Spectrum and have come across a small problem. I belong to a video company and was asked to write a program in Basic which would hold in its memory such things as accounts and film titles. The problem is that I can't program the computer to change accounts without going into the program.

It asks if I would like to change an account, but when I reply 'yes', although it changes it, it goes back to normal when I go back to the menu. I looked in the manual but it only keeps on about DIM. Do I use DIM?

David Scott, Littlehampton, West Sussex

A. We assume what you want to do is to design a system that will allow you to update figures, hold them in memory, and save them to tape but it's not exactly clear what you're doing at the moment.

It sounds suspiciously like you're inputting numbers, and then you've got a rotuine for printing them on screen without organising the actual storage of them in memory. If this is what you're doing, it's a bit ... um ... dim.

The manual does indeed go on about DIM, but not in a form that beginners can automatically understand. The basic principle is simple - if you say:

DIM a(30,30)

you're reserving a space in memory for 30 rows by 30 columns of numbers. This means that you're drawing up a large sheet of squared paper in the computer's memory, and you're labelling it 'a'. Now you can write numbers into the boxes in your squared paper by saying LET a(x,y) = z.

This will fill the number z into the box in the yth row of the xth column in your notional table, just as it would on the screen if you tapped in PRINT AT x,y;z.

So the obvious way of dealing with this is to write the data to the screen at the same time as you're writing it to the array in memory. It's handy to use the same coordinates, but if you want to insert hearings for the companies involved at the top or the left margin you'll have to bear in mind you'll be displacing the screen coordinates.

The companies' names are best stored in a separate string array, which would be DIMensioned as the largest plausible number of companies by the longest company name, so you'd have a representation of two arrays on the screen.

David Scott