Programming is the process of writing instructions that tell computer hardware what to do. It’s fundamental to computing, yet to most people it’s an impenetrable and arcane art. It needn’t be a mystery, though. It would be ridiculous for us to suggest that non- programmers could soon be writing software to rival Microsoft Word or Excel , but understanding the basic principles isn’t as difficult as you might think.
If you’ve never dabbled in computer programming, here’s your opportunity to gain an appreciation of what’s involved. In the first of a two-part series, we’ll teach you the fundamentals so you can start writing programs for your PC.
Many programming languages are available; here, we’ve used Basic (short for beginners’ all- purpose symbolic instruction code). We chose this language for its relative simplicity. All you need to know before you begin is the definition of a program: a list of instructions that is carried out sequentially and tells the computer what to do.
One drawback with Basic is that it’s an old language. As its name suggests, it’s also rather basic. In the 47 years since Basic was introduced, many variations have been produced. SmallBasic , which we use in the following workshop, is just one of them (don’t confuse it with Microsoft’s same-name product: Small Basic ).
SmallBasic contains plenty of instructions that weren’t in the original Basic. With the exception of graphics, we’ve avoided using most of these, instead helping you get to grips with the instructions that will be familiar to all versions. Because the original Basic didn’t include facilities for graphics programming, graphics statements are proprietary in all versions of Basic. The way graphical output is produced in SmallBasic is thus different from many other versions.
>>Using SmallBasic to program software >Step 1: Before writing any software we’ll run a sample program in SmallBasic. Choose File, Open and select plasma.bat from C\Program Files (x86)\SBW32\FLTK_0.10.7\graphics. The program will appear in a tab labelled plasma.bas. Click Run in the bottom status bar, then select the Output tab.

>Step 2: Select the plasma.bas tab and change ‘const’ to ‘cons’ on line 10. This will go from red to black, since it’s no longer a Basic’s keyword (more on this later). Click Run and you’ll see the error message ‘Undefined sub/func code: cons’ with the status line indicating it’s on line 10. Get used to seeing these error messages.

>Step 3: Select File, Close to get rid of the sample program. Next, select the untitled.bas tab, enter the code shown above and click Run. ‘HELLO WORLD’ will appear in the Output tab. You’ve written your first program. It’s not compulsory in SmallBasic, but we’ll use line numbers so that it’s easy to add commands later.

>Step 4: PRINT is a Basic keyword, and tells the PC to perform an action. Basic allows you to create and name variables that contain a value. We’ll illustrate this using ‘N’. Begin a new program and enter the code shown above, then click Run. The three ‘PRINT N’ statements produce different results because N’s value changes in lines 3 and 5.

>Step 5: The statement ‘N = N + 1’ is an instruction that tells the computer to change the value held in N to one greater than it was previously. Try the program in the screenshot above to see some other arithmetic functions, namely subtract (-), multiply (*), divide (/) and ‘raise to the power of’ (^).

>Step 6: Create a new program and enter the code shown above. Work out what you think the answer will be, then click Run. You probably added 10 and 2, which makes 12, then multiplied it by 4, resulting in 48. In fact, the answer is 18. Basic completes multiplications and divisions before additions and subtractions.

The concluding part of this post shall be publish tommorow...

0 comments:

Post a Comment

Popular Posts