September 26, 2022, 01:30:53 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Programming 1 - A Console Window

Started by GWS, April 27, 2010, 02:17:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

April 27, 2010, 02:17:52 PM Last Edit: April 29, 2010, 10:57:21 AM by GWS
Programming 1.

Getting Started

This guide aims to get you started programming in Creative Basic.  It will deal mainly with programming principles, but will examine features of CBasic as required.  Full details are easily found in the Creative Basic User's guide in the Help pages.

Why use this language? It's down to preference really, but having tried pretty well all languages out there, I always come back to this one. Besides which, it's absolutely free. It has been well tested over a period of 10 years - it's simple and a pleasure to use.  If you learn the principles of coding in this language, those principles will stand you in good stead if you choose to use some other language.

To save you typing lots of code, most of the examples we use can be selected, and copied and pasted from this text.

We are working with the Windows system, so the first thing we need is to create an open window in which to test our early example programs.

Skeleton Console Window

Start CBasic and open a new program using the â€ËÅ"File - New - source file’ menu.
You now have a blank editor window. Type in the following instructions:

________________________
openconsole



do:until inkey$<>""
closeconsole
end

________________________

Click on the green Run button, or use the â€ËÅ"Build â€ââ,¬Å" Run’ menu, to start the program.

This small program has created a working window known as a â€ËÅ"console window’.

This type of window has limited graphical ability, but it will be adequate for us to test a number of programming commands.

To close the window, simply press any key.

What do the program instructions mean?

The â€ËÅ"open’ and â€ËÅ"close’ console commands are obvious. The first opens the window, and the second closes it again. The command just before â€ËÅ"closeconsole’, will be examined later.  For now, note that it waits for any key on the keyboard to be pressed, closes the window, and ends the program.

The â€ËÅ"End’ command is present in all programs as the last instruction. It closes all open windows and files, and terminates the program.

Save the program in a working directory somewhere, using the â€ËÅ"File â€ââ,¬Å" Save As’ menu.  Give it a name such as â€ËÅ"cbcons.cba’, so that you can load it again whenever you wish to open a skeleton console window program.

We will be using the skeleton program to test a number of programming examples.

In the test programs, we will be inserting test statements in the blank lines between the â€ËÅ"openconsole’ statement and the closing three statements.

Notice that in the CBasic editor window, most of the commands are coloured blue. This is known as syntax colouring.

Every statement that is a built-in component of CBasic is highlighted in blue. Comments are coloured green, and some other keywords are coloured red.  These colors can be changed using the â€ËÅ"File â€ââ,¬Å" Editor Options’ menu.

You have written your first program, but at the moment it does nothing. So let’s get it to do something useful.

Click on one of the blank lines following the â€ËÅ"openconsole’ command and type the following instruction:

Print "My name is John Smith"


Click on the green Run button, and Hey Presto, we have something useful.

We have used the â€ËÅ"print’ command to direct text to the screen. As you see, the required text is enclosed in quotes.

Now try this small change:


Print "My name is "
Print "John Smith"



Run the program again, and you will see the text is now on two lines.

Finally, try this:


Print "My name is "
Print
Print "John Smith"



Easy isn't it. If you wish, you could save the test program, using the â€ËÅ"File - Save As’ menu, and give it a new name, so that it doesn't overwrite your original console skeleton program â€ËÅ"cbcons.cba’.

I would suggest that you use a separate directory called â€ËÅ"CBWork â€ËÅ" or similar, in which to save your test programs.

Try to keep a separate directory for each of your projects.

End of Programming 1
_____________________________________________________________


OK, there's a first bit.  Not a lot, but it's a start ..  

The idea now would be to seek any questions from anyone starting out in programming - such that replies would be available from myself, or anyone else who wished to jump in ..  

Anyone new to this site or to programming, don't be shy - just get posting and open up a conversation.  Even the simplest questions are useful to help others who might get stuck over the same points ..  
Tomorrow may be too late ..