NSBasicCE Tutorial

Lessons in NSBasicCE


vns_textmedium

Programming Using NSBasicCE

All content (c)1999-2007 Serg Koren and VisualNewt Software.

All rights reserved.

List of Articles:

  1. The Package and Installation.

    Discussion of the history of BASIC, and how it relates to MS VisualBasic and NSBasic. Steps needed to install NSBasic on a Casio-E105 are described.

  2. The Editor and Modes.

    A complete discussion and exploration of the NSBasic programming environment detailing every menu item. A description of Immediate and Programatic mode programming with examples.

  3. Objects, Properties, and Methods! Oh My!

    A beginner's explanation of Object-Oriented-Programming (OOP) with emphasis on NSBasic.

  4. CommandButtons.

    An explanation of how to use CommandButtons in NSBasic.

  5. MSGBOXes, SUB and FUNCTION

    What SUBroutines and FUNCTIONs are and how to use them, basic parameters, and the MSGBOX user-interface widget.

  6. CheckBox and Variables

    A discussion of variables, how they are stored in memory, how to use them, and the CheckBox widget.

  7. Strings and COMBOBOX

    We talk about what strings are, and how to use them and combine them. We also look at the ComboBox object.

  8. Dissecting Strings and the Date Object

    We follow up our discussion on strings and talk about taking them apart. We also look at the buggy and barely usable Date Object.

  9. Arrayed Things and the INPUTBOX

    This article deals with arrays, what they are, how to set them up, and use them. We also talk about the INPUTBOX and what it is good for.

  10. Decisions, the Label and ListBox

    Getting your program to decide things for itself, and how to put labels on your screen, along with the ListBox object.

  11. DejaVu Again

    Getting your program to loop, and the OptionButton object.

  12. FOR EACH, INSTR, and the PICTUREBOX object

    A powerful new kind of loop, searching for a string in a string, and graphics.
  13. PRINT, REDIM, and the TEXTBOX object

    Printing information to the screen, resizing arrays and text objects.

nsblogo2_textmedium

ARTICLE 1--The Package and Installation

Programming Using NSBasicCE

ARTICLE 1--The Package and Installation

All content (c)1999, 2002 Serg Koren.

All rights reserved.

If you know BASIC and you've already gotten and successfully installed your copy of NSBasic, congratulations! You can skip the rest of this article and check back next time. However, if you're a total newbie at things-computer, this is for you. We'll step you through getting NSBasic installed on your Casio E105 and working. First, however, we'll start with a brief description of BASIC in general (NSBasic specifically) and what you get.

BASIC

BASIC is one of the older computer languages, and exists on pretty much every computer platform available. It's called BASIC because it is--basic that is. It's usually the first language people learn when they want to learn programming. When it first came out the only other languages available on pcs (which were new then) were assembly and machine language. Machine language is just that--its the language the machine (hardware) understands. Just 0s and 1s, and you programmed by toggling physical switches. Each switch when on represented a 1 and when off a 0. So a bunch of switches on the front panel of your pc might be set to:

01101010

which meant something simple to the computer (like remember a 2 because I want to add something to it). No fooling! Programming was hard and tedious. Assembly language was a big step forward. Somebody got smart and figured out how to hook up a keyboard to the pc. But you could still only program at a very low level. Assembly language was easier to program, but it was difficult to read and understand. For instance the switches (bit pattern) was replaced with:

MOV A,2

which meant, MOVe 2 into the Accumulator. Accumulator? An accumulator holds a single number to be accumulated (added to) with another. You can only do addition when you come right down to it. To subtract you'd add a negative number...but that's another story. Multiplication and division were done via multiple adds (or adds of negative numbers).

Then someone thought, hey wouldn't it be neat if we could program in something closer to English? And BASIC was born. BASIC used simple understandable English words to denote commands to the computer. Additionally, simple math was born via the normal school symbols +,-,/,* (well keyboards don't have a multiplication symbol, so they replaced it with an asterisk.)

And everyone loved it (and pretty much still do); but as new computers and companies started up, each wanted to make their own BASIC, and they wanted it to be better (or at least different from) than other BASICs out there. So BASIC begat BASIC begat sort-ofBASIC begat well its close to BASIC. A plethora (I've always wanted to use that word in an article) of BASICs emerged. All were similar, but few would run on each other's machines. Babylon reborn!

Well it didn't quite work like that, and it's not quite that bad, but close enough. If you're at all familiar with computers you've probably heard of "Standards" or "Standard Committees". Standards are a set of rules that make something consistent. It's a big thing now. Computer stuff needs to be "standard" so that you can buy a copy of X-BASIC and it will run on Y-Hardware. You don't have to pay big bucks for Y's version of BASIC that ONLY runs on Y-Hardware. The problem is, is that BASIC has a fairly weak standards committee (a bunch of people who make up the standard), so you still see X-BASIC that ONLY runs on X-Hardware.

So what does all of this have to do with NSBasic? Well in one word, Microsoft. Microsoft is well known (and infamous) for having an ego. They are so big, they feel that their way IS (or at least should be) a standard. I won't start here, but you get the point. The problem is, is that WindowsCE uses a version of BASIC built-in that is similar (although not identical to) BASIC (VisualBasic) on the desktop. Both have similar guts, but not identical. NSBasic uses the guts to do what it has to do to get your program to run. So if you're new to WindowsCE, but familiar with VisualBasic on the desktop, you'll be somewhat surprised (I hope) to hear that NSBasic isn't VisualBasic. NSBasic/CE is a version of BASIC. There are tons of BASIC and VisualBasic books out there (just check your local Amazon.com). The problem is, is that although NSBasic/CE is similar to BASIC, you can't just pick up a BASIC book type in the code you find and hope it runs on your Casio.

Hopefully, the above will save you some hassles in terms of running out and buying a ton of VisualBasic books and wondering why the code you typed in doesn't run. The books are useful, they give you ideas and ways of doing things, but save your money. If you don't already know BASIC (any flavour), then you're better off without them. The books will only confuse you. Which brings us to the NSBasic/CE package...

The Package

NSBasic/CE comes in two pieces. You get a CD-ROM full of NSBasic, sample programs, "goodies", and other stuff. The second piece is the compact manual. If you're new to NSBasic/CE, this is your best friend. It doesn't tell you how to program, but it tells you what you can do and how you can do it. It's a reference manual, meaning that it describes each of the commands that NSBasic has. It's a good exercise (and no not boring) to just sit down and read the manual cover to cover when you first get it (one of the few manuals I suggest you do this with). It's well written and even if you don't know anything about BASIC, you'll pick up a lot just by going through it once. Don't try to memorize everything or learn it all. Just read it like a novel. That way you get a feel for the language, and what you can do. So, when you say "gee I wish I could do..." you'll remember that you saw something like that in the manual. Basically, if you don't know what's in the manual, you don't know that you can do it easily.

The manual isn't perfect. It doesn't have a few things which are part of NSBasic/CE, but it has most of it. The missing pieces you can get from the website's support page. These pieces are a bit more advanced usually, but you should check out the support page and browse through the downloads and tech notes pages. Also, you should make it a habit to visit the web message board that NSBasic has set up. This is your 2nd line of defense. Here you can see what others are doing, what problems they are having, and what solutions are offered. You can also post your own problems, questions, and suggestions. Don't be shy. Even total newbies are welcome. And, the people of NSBasic Corporation watch the board regularly and post useful stuff. The board may be a bit intimidating because there is so much stuff there (and it's not well organized) but its a wonderful resource. Ok, you've opened up your box from NSB and have stared at the CD and read the manual, and browsed the board. Time to install...

Installation

Ok, first things first. If you haven't done so already, make sure you have Windows Services (now known as ActiveSync 3.0...PLEASE upgrade your WindowsCE Services to this if you haven't done so...it's lots slicker and faster and fixes a lot of problems). You can find ActiveSync at: http://www.microsoft.com/windowsce/products/highlights/activesync.asp

Make sure you can successfully sync your Casio to your desktop. (Yes I know this is very basic, but if you can't do this you can't do anything else.)

Ok, now pop your NSBasic CD into your drive, and double-click the Readme document you find in it to launch the installer. The installer is set up to run from within the Readme document. Read (or at least browse) the readme document to see what's new, what known problems exist in NSBasicCE, etc.

Here's the confusing bit. The Readme document and the CD let you install NSBasic on a bunch of different types of hardware. HP Jornadas, Casios, Mobilons, etc. You must make sure you install the correct version of NSBasic for the hardware you have, or nothing will work and you'll wonder why. I once in a rush installed NSBasic and it didn't run until I realized I'd made the wrong choice during the installation. Be careful.

Since this article is about Casios, we'll walk through the Casio installation. The Casio E105 is a Palm-size PC. Luckily, this installation option is the first one found on the Readme document. "Palm-size PC Installation Instructions." This consists of seven steps (6 if you're not upgrading). Do these in order to avoid problems. Here's the second complicated bit--this is as complicated as it gets...which isn't very. Click on each link in turn and make sure you choose the Run this program from its current location option. Otherwise nothing will install and you'll wonder what happened. Each step will bring up your Active Sync (or WindowsCE services) installation dialog. Just follow the prompts and make sure you answer Yes to install in current directory. You may be wondering what gets installed. The first step, Basic Setup installs the NSBasic editor, help files, pretty much the guts of NSBasic/CE. Goodies Setup installs sample files. The Scripting Engine setup installs the Microsoft "guts" we mentioned earlier. The last step, System Files, installs various add on pieces that either NSBasic uses directly or you can use from your own programs.

Don't' forget to enter your serial number into the Installer application on your Casio when done.

That's it. Uh no not really. There's one step that you need to do (which isn't documented). Once you've installed NSBasic/CE on your Casio, log onto the NSBasic website and download any upgrades/updates to your version from the support page. Make sure you get the latest version if you didn't get it on the CD. Install any updates (you may not need to).

That's it. Now you're done.

I'm sure you're antsy to program, so we'll quickly run a test program to make sure everything is installed ok. This is your typical (and highly boring) "Hello world" program that always gets written when you first start learning a language...don't ask why, it's pretty stupid, but it works.

Start NSBasic from the Start menu of the Casio. You'll find it under Programs, labeled BASIC. This will bring up the NSBasic editor. For now ignore everything and just type or copy/paste in the following line into the blank area of the editor:

MSGBOX "Hello there. This is NSBasic/CE"

Double-check for typos. Then in the menubar hit the right-arrow button. This will run your program. If everything works properly you should get a new window pop up with the message "Hello there. This is NSBasic/CE". If you get the message "Microsoft VBScript compilation error - line 0, char 10 Unterminated string constant" (or something similar) you probably typed a ' instead of a " (or forgot one of the quotes). Fix the typo and try again by hitting the arrow button. If you get the message "Microsoft VBScript runtime error - line 0, char 0 Type Mismatch: " (or similar) that means you misspelled MSGBOX. Fix the typo and try again.

You should at this point have the dialog with "Hello there. This is NSBasic/CE". If you fixed the typos and you still get an error message you probably skipped an installation step somewhere. You should reinstall and try again. If after reinstalling and trying the above program you still have problems, you probably have a real problem with NSBasic or your setup and you should post a message on the webboard explaining the problem and the exact message you get.

Hopefully, and in most cases you'll get the above program to run. As I said, it's not exciting but it proves you've got a good installation of NSBasic. We won't explain what the program does right now. Just believe me, you wrote your first program. You can close the dialog using the close or Ok button. This will leave you at a blank screen. Close this screen using the close box and you should be back at the NSBasic editor with your program as you typed it. You can quit now. You don't have to save the program, if you don't want.

Well, that's it for this installment. Hopefully, you're still here. Next time, we'll go over the NSBasic editor, and describe what all the menus do, and do some more interesting programming for the beginner.

nsblogo2

ARTICLE 2--The Editor and Modes

Programming Using NSBasicCE

ARTICLE 2--The Editor and Modes

All content (c)1999, 2002 Serg Koren.

All rights reserved.

Welcome to the second installment of NSBasic on the CasioE-105. If you're joining us late you may want to peruse the Introduction if you haven't done so already and the archived article at: http://www.VisualNewt.com/CE/NSB/AvantGo/Archives

This time around I'll discuss the NSBasic editor, the modes that NSBasic works in and some introductory material on Objects. In addition we'll do some fairly basic (excuse the pun) programming. Most people tend to jump into programming with a full blown example program and dissect it to explain how to program. I'm going to take the bottom up approach and start simple and work our way up so that I don't lose anyone along the way. You can't build a house from the top down, so we're going to lay a good foundation first.

The NSBasic Editor

If you haven't done so, you want to install NSBasic (see the first article) and start it (Start/Programs/Basic). The program that runs is the NSBasic Editor. This is where you will spend most of your time writing and developing your programs. It has the principle features of most editors, but in addition it has features specific to running and debugging your programs. Debugging, I'm sure you probably know, means finding problems in your program and fixing them. We'll have a whole article or two on debugging.

Let's go through the editor and describe its features. Along the top is the menubar with all the functionality and commands available to you. The large blank spot is where you can 'type' your programs. The menubar has some familiar features under the File and Edit menus; I'll only describe the things specific to NSBasic.

Under the File menu, there is an item labeled Encryption ON or Encryption OFF. This is a toggle menu and it switches between the two based on the source code you happen to be editing. You can also manually toggle it. Try it. What this menu does is save your program in either an encrypted or normal (Encryption OFF) format. If Encryption is OFF, then anyone can see and read and understand your source code (your program's commands). This is useful if you want to distribute your program on the Internet and you want people to see how you wrote your program. If Encryption is ON, then if you distribute your program on the Internet, then people will only be able to run your program. They won't be able to see your source code, or see how you actually did things. You on the other hand, will always be able to see your own programs no matter how they are saved (Encryption ON or OFF). The menu not only tells NSBasic how to save a program, but also reminds you how a program was saved by you when you Open it in the editor. So if you saved a program with Encryption ON, so people won't see your source code, and you go into the Editor and open the source file, Encryption will be set to ON. (You can switch it to OFF if you want to let people see the source code, or vice-versa). Try tapping a few characters into the editor and saving the file with Encryption ON and save another copy with Encryption OFF. Now quit the editor and restart it. Using the File/Open menu open each of the two files you saved and look at the Encryption menu. One should be ON and the other OFF. You can try switching the settings and resaving the files, and then reopening them to see the effect. It's fairly simple. The thing to remmeber is that the person who wrote the program always get to see the source code on their own machine, no matter how they saved it.

Ok, under the Edit menu there are two unfamiliar items: Goto Line, and Overview. GotoLine brings up a prompt and lets you enter a line number. The editor will then move the cursor to that line number. This is useful if you get an error and the error gives you the line number where the error occurred. You can use this feature to jump right to it. Overview is similar to Goto Line in that it lets you jump to a given spot in the program. Instead of jumping to a line number, however, it lets you jump to either a subroutine or function name. Subroutines and functions are "chuncks" of programs that are given names. The names identify and let you reuse a "chunk" from more than one spot in the program. We'll go over this later, but for now you can see how this feature works. Using File/Open, open one of the sample programs that come with NSBasic. Then use the Edit/Overview menu item. Depending on how big the program is, you should get a list of subroutines and functions in a second or two. You can scroll through this list (if the program is long enough). If you don't get a list, then the program you selected has no subroutines or functions. Just open another sample until you find one that has these. Once you have a list up, select one of the items in the list and tap the Goto Line button (which really should say "Go to routine") The program will automatically scroll the editor and select the line with the name you selected. The Overview feature lets you jump to places by name and is useful for long(er) programs.

The Tools menu has a lot of powerful features, so we'll take them one by one.

Format: The Format menu item tries to clean up your program's formatting. It lines things up and adds spaces where it thinks they are needed and basically "beautifies" your program's source code so its easier to read. It's not perfect and some people don't like how it does it (everyone has their own "style" of writing code...some people like lots of spaces, others don't...some like all capital letters, others don't.). But Format does a decent job. Its a good idea to run Format after you've written a lot of code, since formatting the code can sometimes show you were you might have a problem, if things aren't lined up the way you would expect. We'll talk about style later.

Run: This has a couple of submenus: Run, Execute Function, Trace, and Step. You'll use Run most often; it tells NSBasic that you want to try to run (execute) the source code you have in the editor. Try this: File/New to get a clean edit window, and then Tools/Run/Run . What happened? Your menu seems to have disappeared. Actually, it hasn't. You've told NSBasic to run your program, but you don't have one. Actually, you do, but it doesn't have any lines. NSBasic by default, creates a new blank window with a close box for every program. This blank window is where you will put all those keen (sorry for the word) features such as checkboxes, menus, pictures, fields, buttons, etc. that you find in programs. This is the window that contains them. Right now you can't do much with your empty window except close it via the close box in the upper right. So, close it, and you'll get your NSBasic editor back. So, if you're just starting out, and you mysteriously lose your menubar while in NSBasic, don't panic. Just close the window and you'll get back to NSBasic and your program.

Execute Function is disabled. This is a debugging feature. Once your program is running there are ways to interrupt it and tel it to stop where it is. You can then switch back to NSBasic (using the a task manager you can download from various sites) on the taskbar at the bottom of the Casio screen. At this point, Execute Function will be active. You can choose it to specify a subroutine or function name (like the Overview), but instead of jumping there, NSBasic will try to run that "chunk" of program as if it were a mini-program. This is useful for seeing if a given subroutine or function (I'll stop using chunk, since I think you know what it means by now), is working properly. Programs get complicated fast, and the more subroutines and functions you can break your progam up into, the easier it is to find problems and keep from writing the same code over and over and over again. Think small. A good rule of thumb on the Casio is that your subroutines and functions probably shouldn't be longer than one screenfull of source code. Next!

Trace: Trace is another debugging feature. It shows you which line NSBasic is running as its running it. Two warnings with Trace. It slows the program down a lot, and it has a problem. Any program that has a line "OPTION EXPLICIT" will cause Trace to display an error message. You can temporarily comment out (remove) the OPTION EXPLICIT line and try again (don't forget to uncomment (put back in) the OPTION EXPLICIT line when done. Try this with the Benchmark sample in the Samples folder. Trace displays the line number, and the actual source code on that line as it executes it. Compare the results by using the Tools/Run/Run item with the Tools/Run/Trace item. Why is Trace useful? If your program is going somewhere and you think its should be going somewhere else, Trace can help you find where its going wrong.

Step is a more powerful (but slower) version of Trace. It has the same problem with OPTION EXPLICIT as Trace does. Step lets you stop after NSBasic executes a line and see what it did. Try it with the benchmark program (remove the OPTION EXPLICIT again). Once you do a Tools/Run/Step you should get a window with Line 1 at the top, the actual line being executed right under that, a big empty field on the left and two buttons, Execute and Continue on the right. The line number and the line are about to be executed; that means, NSBasic hasn't actually run the line yet. Try hitting the Continue button. The window should now display Line 2. Tap the Continue button a couple of times. You can step through the entire program this way to localize where a line has gone wrong. The big input field lets you type in a temporary NSBasic command and run it with the Execute button. This is useful for trying a simple fix to a line you've discovered is wrong, or for displaying the contents of a variable (a value) to see if your program computed it properly. Unfortunately, Step doesn't let you quit easily. There should be an Abort button. To get out of Step mode and return to the NSBasic editor, type the word BYE into the empty field on the left and hit the Execute button.

Those are the Run submenus. They let you run your program, as well as to help you debug it.

The next menu item on the Tools menu is Execute Code. This feature lets you try a little bit of NSBasic code without actually putting it into your program. This is useful for trying something out before putting it into a function or subroutine if you aren't sure it will do what you think it should do. Try this to see how it works: Tools/Execute Code to bring up a mini-editor. Type in the line:

MSGBOX "I'm learning to use the NSBasic editor."

Double-check the typing and quotes, and exeucte it. But there is no button to execute it, is there? Well what happens when you close the mini-editor, using the Ok box in the upper-right? It runs the code in the mini-editor. If you get an error message, simply close the error window, close the main window (the empty one usually) and then do Tools/Execute Code again. One nice thing about this feature is that once you close the window, your test code in the mini-editor is still there so you don't have to keep typing it in from scratch. Fix your typos and try again. So, Execute Code lets you try snippets of code before you actually put it into your main program. One problem with Execute Code is that once you have the code working in the mini-editor there is no easy way to transfer (copy/paste) it into the main editor. You have to retype it in by hand.

Show Variable on the Tools menu is another debugging feature and is only active while you are running your program. Once you've interrupted your program, Show Variable is active and brings up a window where you can type a variable name and display its value (contents).

Tools/Stats just gives you how many lines your program is and how much space it takes up on your Casio. Load in a sample program and select Tools/Stats. The word "script" in the message maybe confusing to you. A scripti s a set of commands to be executed, so in that sense NSBasic is a scripting language. There are other meanings of the word "script" in computing, but we won't go there just now.

The VisualDesigner item under the Tools menu is a fairly new addition to NSBasic and deserves several articles on its own. The VisualDesigner lets you design the GUI (checkboxes, menus,etc) for your program without having to write much code. But since we're trying to work from the bottom-up, we'll leave the VisualDesigner for future articles.

That's basically the NSBasic editor. The only other feature you should be aware of at this stage is the arrow button on the menubar. This is a shortcut for Tools/Run/Run. Pressing this button will start your program executing.

NSBasic Modes of Execution

Modes of execution refers to ways in which something gets done. This relates to the word "scripting" we mentioned above, and deferred until now. First some explanations and definitions.

NSBasic is an interpreted language. The other major type of language is compiled. An interpreted language is one that is read and executed line by line. You write a program with lots of lines in it. Each line is a comand. The interpreter takes that line and translates it into an intermediate language. When you run the program, the interpreter then translates the intermediate language into its effects (what you want the line to do). A compiled language is one where all of the program lines are "compiled" or translated into a form the machine it is running on understands. You don't need a program to interpret the program. This means two things for you as an aspiring NSBasic programmer. NBasic is interepreted, so any program you distribute over the Internet or to your friends needs something to interpret the program to run. This is provided in the NSBasic "runtime" module. This is a program that knows enough to run a program that's already written, but isn't powerful enough to let someone write a program. So, if you distribute a program, the person running it either has to have a copy of (a) NSBasic, or (b) the runtime module. (It doesn't hurt if he has both). The second thing this implies is that interpreted programs are a bit slower when they run than compiled ones. This isn't critical usually, but if you're trying to write a program that has to be as fast as possible, then NSBasic isn't the way to go.

What does this have to do with modes? Well because NSBasic is interpreted, it really has two modes of operation: immediate and programmatic. Immediate is just what it sounds like. You enter a line of code and execute it immediately. The programmatic mode gets run when the person runs the program. This is a very fine distinction, but an important one. Usually it doesn't matter, but in some programs it does. For instance, if you were to write a program with no functions or subroutines, your entire program would be running in immediate mode whenever you ran it. Anything in a subroutine or a function runs in programmatic mode. Another way to look at this is whenever you use an immediate command (one not in a subroutine or function), it gets executed right away and is really useful if you want to tell NSBasic something (as opposed to having your program do something). This is another definition of "scripting"; you're telling your programming enviornment (NSBasic in this case) to do something, instead having your program do what your program does. You'll find, as we go on, that some commands in NSBasic are for use in Immediate mode, while most are useful programmatically. For example the OPTION EXPLICIT command we'll see later is a command to NSBasic to force you to do certain things when you program, instead of when you run the program its found in. So what about our MSGBOX program? The way we were using it it's an immediate command (it's not in a subroutine or function), and is really telling NSBasic to display a window. However, you can (and will) use MSGBOX inside of functions and subroutines. That way, it would run programmatically, to tell your program to display the window. Yes it's a fine line, and one you can usually ignore. Just remember that some commands are only useful outside of subroutines and functions. Another term for immediate mode is command level or interpreter level mode.

A Bit of Code

Ok, we promised a bit of code. This example shows you the difference between immediate and programmatic mode. We won't explain it, but will say that the second window is programmatic, while the first is immediate. Start up NSBasic, and type the following program in. Save it (and call it whatever you would like). Then tap the right arrow on the menubar or execute a Tools/Run/Run command. Again if you have an error message come up, double-check for typos (careful to use double-quotes). Tap Yes to see the programmatic MSGBOX. What happens when you tap No instead in the first window?

' Everything inside a SUB or FUNCTION gets done programmatically and waits to be told to run by your program.
SUB ProgrammaticMsgbox
MSGBOX "This is the programmatic one."
END SUB
' Everything outside a SUB or FUNCTION gets done immediately (as soon as you hit Run).
result = MSGBOX ("This is an immediate mode MSGBOX. Tap Yes to see a programmatic one.",vbYesNo)
IF result = vbYes THEN
	ProgrammaticMsgbox ' tell our programmatic MSGBOX to run now
END IF

Ok, a question to think about regarding this simple program. Why don't you get the window with "This is The programmatic one." first? Lines in programs get executed (run) in sequence from the first (top) to last (bottom). We'll answer this question and discuss the above program next time, along with actually getting into more programming, now that we've gone over the Editor.

Cheers!

nsblogo2

ARTICLE 3--Objects, Methods, and Properties! Oh My!

Programming Using NSBasicCE

ARTICLE 3--Objects, Methods, and Properties! Oh My!

All content (c)1999, 2002 Serg Koren.

All rights reserved.

Welcome to the third installment of NSBasic on the CasioE-105.

This time around I'll discuss some major concepts in computer programming today, namely the concepts of object-oriented programming (don't worry, I'll go slow). But first, I left off the last article with a question.

Leftovers from Last Time

Given the following code snippet (which you can enter into NSBasic...see the last two articles on how to do this).

'---start code here---

' Everything inside a SUB or FUNCTION gets done programmatically and waits to be told to run by your program.
SUB ProgrammaticMsgbox
MSGBOX "This is the programmatic one."
END SUB
' Everything outside a SUB or FUNCTION gets done immediately (as soon as you hit Run).
result = MSGBOX ("This is an immediate mode MSGBOX. Tap Yes to see a programmatic one.",vbYesNo)
IF result = vbYes THEN
	ProgrammaticMsgbox ' tell our programmatic MSGBOX to run now
END IF

'--- end code here -----

The question I asked was: Why don't you get the window with "This is The programmatic one." first? Lines in programs get executed (run) in sequence from the first (top) to last (bottom).

The answer relates directly to the last article. First thing I should mention is that any line starting with a single-quote (') is a comment, and ignored by NSBasic. It's a way of reminding you or explaining to others what your program code is actually doing. Use comments extensively in your program. I'd go as far as to say, that you should probably have more comments than code (but I won't hold you to it).

Anyway, the answer is that the MSGBOX "This is the programmatic one." doesn't show up first because it doesn't execute UNTIL the SUB (subroutine) is called (executed). Where does it get executed? It gets executed LATER in the program when the result = MSGBOX(...) line gets called. And this gets called in IMMEDIATE (see the last article) mode, but only when you tap the Yes button on the first dialog (This is an immediate mode MSGBOX. Tap Yes to see a programmatic one.)

So in short Immediate mode commands get executed right away. Programmatic mode commands (those in SUB or FUNCTION) only get executed when called.

This leads to the ultimate conclusion that all NSBasic programs ultimately get run from an Immediate mode command somewhere in the program. I'll give you a general guideline to better programming:

The better (more organized) your NSBasic program is, the fewer Immediate mode commands it has in it.

You can't get away from Immediate mode commands, but you should only use them when you have no other way to go. We'll talk more about this next time, but now some more concepts and some more code!

Object-Oriented-Programming: Object, Methods, Properties, Events

Object-Oriented-Programming (OOP for short) is the way to go nowadays. It's the big thing. It's a way of thinking about programming. The little bit of code we've seen so far has not been OOP. The stuff we've seen is called "procedural programming" (sorry no acronym for this). It's procedural because it has procedures (also known as SUBroutines and FUNCTIONs). The code gets executed line by line from the top down (with sidetracks as SUBs and FUNCTIONs are called). It's procedural because you're basically doing instructions to get, massage, and output data by issuing commands.

OOP thinks differently. Instead of thinking about data and what you do with it, for something to happen, you think about objects (real such as cars, loaves of bread, etc., and psuedo-objects such as arrays, lists, and even numbers.). In OOP you define objects that represent real (and not so real) things in the world. Each object you define knows how to do what the object does. A car object would know how to speed up, slow down, turn, brake, stop, etc. How does it know? Once you define an object (car) you define the things the car object knows (speed up, slow down, brake, etc.). These "things" the object knows how to do are called methods. So Objects have Methods which are things that Objects know how to do. In other words, you wouldn't have a Method in a car Object called "MakeToast", because a car doesn't know how to make toast (usually)--a Toast Object would have a Method called MakeToast. How many Objects can you have? As many as you need. How many Methods can an Object have? As many as your Object needs. Ok. So we have a car Object and it knows how to speed up using a SpeedUp Method. How fast is the car going? How does the car Object know? Via a Property. Properties are characteristics of the Object. A car Object would have a Speed Property; it would probably also have an Acceleration Property that told it how fast the SpeedUp property was accelerating the car. A car Object would also have Make, Model, Color, Year properties. Any characteristic that the car Object would have to worry about and use. If the car Object didn't care what Color it was, you'd leave out the Color Property.

So, in OOP you design (or in NSBasic you use) Objects, that have Methods that makes the Object do things, and Properties that tell you things about what the Object is doing at that instant (the Speed may be one thing--30mph now--but may be 105mph later.) Ok. There are two more OOP concepts we need to worry about (there are lots more things to know about OOP, but this is really all you need for NSBasic. How do we tell an Object it should do something? We send the Object a Message. For example, to tell our Car Object that we want it to speed up, we might send a "speedup" Message to the Car Object. The Car Object knows that this means it should call the SpeedUp Method which really does the work of speeding the car up. The last concept is one of Events. An Event can be thought of as a trigger that causes the Object to do something. In our example, the Car Object receiving a "speedup" Message is an Event. The Car Object speeding up, may or not be an Event depending on how it is written. Another type of Event is one caused by the user of the program (you). Tapping on something, typing something, dragging something, are examples of user-generated events. Typically, you have to tell (write code) to tell the Object what to do when the user generates an event.

Phew!

So: Object--->knows how to do something which are Methods

Object--->has characteristics which are Properties

Object--->get sent Messages which cause Methods to execute

Objects-->react to Events (receipt of Messages or user caused events)

That's a lot of info to digest but it isn't too hard to understand. Just a lot of jargon.

You may be wondering now....Why oh why do I have to worry about this stuff? Why can't I just program using NSBasic like we have been? Well to be honest you could, but your programs would really be very primitive and crappy looking. The fun stuff is all done using OOP. The fun stuff in this case being the user-interface (GUI--buttons, menus, edit fields, calendars, databases, etc.)

To take a more concrete NSBasic example, get your NSBasic Bible out (the manual) and turn to the ListBox page. The title on the page has the word Object on the right. This tells you this page describes an OOP Object. (If its a SUBroutine or FUNCTION, it will have SUB or FUNCTION; you will also find STATEMENT which is a simple command in NSBasic, and OPERATOR which is part of a statement.). Ok, a ListBox in NSBasic is an Object, which means it has Properties, Methods and Events. These are all listed at the bottom of the page. A ListBox has Properties named: BackColor, Bottom, FontBold, etc. Properties are characteristics. They determine what your ListBox looks like. You can set these or you can look at them to find out what your ListBox looks like. Methods supported by a ListBox include Hide among others. So our ListBox Object knows how to Hide itself (make itself invisible). Events of a ListBox include Change, Click, DblClick, and GotFocus. Hm...no Hide event, no MakeInvisible event. Why? Because typically, the ListBox doesn't disappear as soon as a person clicks on it. That's a key there! "Clicks on it" So how do we get a ListBox to hide itself? Well we use the Hide Method, by sending the ListBox a Hide message. How do we send messages? We use the name of the Object a dot (period) and then the name of the Method we want to have the Object execute. So, to send a Hide message to a ListBox we would write:

ListBox.Hide

and the ListBox would disappear. We can use the Visible Property to see if it is hidden or not similarly:

... ListBox.Visible ....

The ... indicates other code we aren't going over right now.

Extending this, how do we get a ListBox object to disappear when we double-click on it? Well we use the DblClick Event to send our ListBox.Hide Message.

Events are defined as SUBroutines in NSBasic and instead of the period we use an underscore (_) (I'm not sure why). So our code looks like:

SUB ListBox_DblClick ' respond to a user clicking on our ListBox
ListBox.Hide ' hide the listbox by sending it a Hide Message which executes the Hide Method.
END SUB ' always need an END SUB (or END FUNCTION for a FUNCTION)
 

Cool huh? One thing we bypassed (deliberately) is how to make a ListBox Object. Your program can have hundreds (well tens) of ListBoxes, how do we know which one we want to hide? Well when we create one, we give it a Name. An Object has a Name (which is really a Property). So if we have 2 Car Objects one may be Ted's Taurs, and the other Tom's Taurus. We create an Object in NSBasic using the ADDOBJECT command as listed at the top of the page in the manual. For a ListBox it is:

ADDOBJECT "ListBox",name,xpos,ypos,width,height

"ListBox" is the type of Object we want to create.

'name' is something you provide as the Name for your ListBox. Names in NSBasic have to be strings (enclosed in double-quotes ").

xpos,ypos are the x and y coordinates of where the ListBox will be (Properties) as are the width and height of the ListBox.

Here's your first complete NSBasic program (simple though it is):

'---start code here---
'
' A simple program that creates a ListBox and lets us show and hide it by clicking on it
'
' A subroutine to create a ListBox on the screen
SUB MakeAListBox
	ADDOBJECT "ListBox","MyListBox",50,50,100,100 ' create an empty ListBox
END SUB
 
' A SUB to handle a DblClick Event (a Click event handler) for the ListBox called "MyListBox"
SUB MyListBox_DblClick
	MyListBox.Hide ' Hide MyListBox
END SUB
 
' Our main routine where the main things happen...good to always have one
SUB Main
	MakeAListBox ' create a ListBox
END SUB
 
Main ' our one and only Immediate command for this program to run the Main SUB
'---end code here---

Simple huh? If you can follow the above program, you've gone through the most difficult concepts in NSBasic. Everything else is just learning the individual Objects, and commands (Statements). Browse the manual and look at the Objects (upper right title) and look at the Properties, Methods and Events each type of object supports (many are similar).

Simple quiz for next time. Write a short program (like above), but include a CommandButton Object. The program should have:

1) A ListBox

2) A CommandButton

The program should:

1) Hide the ListBox when you double-click it.

2) Unhide (use the Show method) the ListBox when you tap (Click) the CommandButton.

We'll show you one version of the code (and a simpler version) next time. Next time, we get into real programming and fewer concepts! Stay tuned!

Cheers!

nsblogo2

ARTICLE 4--CommandButtons

Programming Using NSBasicCE

ARTICLE 4--CommandButtons

All content (c)1999, 2002 Serg Koren.

All rights reserved.

Welcome to the forth installment of NSBasic.

This time we go over the most common user-interface object you will use: CommandButtons.

Leftovers from Last Time

Last time I we talked about Objects, Properties, and Methods, and I gave you a simple program that had a ListBox object that hid when you double-clicked it:

'---start code here--- ' 
' A simple program that creates a ListBox and lets us show and hide it by clicking on it 
' 
' A subroutine to create a ListBox on the screen 
SUB MakeAListBox 	
    ADDOBJECT "ListBox","MyListBox",50,50,100,100 ' create an empty ListBox 
END SUB         

' A SUB to handle a DblClick Event (a Click event handler) for the ListBox called "listbox" 
SUB MyListBox_DblClick 	
    MyListBox.Hide ' Hide listbox 
END SUB         

' Our main routine where the main things happen...good to always have one 
SUB Main 	MakeAListBox 
' create a ListBox 
END SUB         

Main ' our one and only Immediate command for this program to run the Main SUB '
---end code here---

I then asked you to write a short program (like above), but include a CommandButton Object. The program should have:

1) A ListBox

2) A CommandButton

The program should:

1) Hide the ListBox when you double-click it.

2) Unhide (use the Show method) the ListBox when you tap (Click) the CommandButton.

And I promised to show you one version of the code (and a simpler version).

Here's the version you probably came up with (or a something very similar):

'---start code here--- 
' 
' A simple program that creates a ListBox and lets us show and hide it by clicking on it 
' 
' A subroutine to create a ListBox on the screen 
SUB MakeAListBox 		
   ADDOBJECT "ListBox","MyListBox",50,50,100,100 ' create an empty ListBox 
END SUB   

' A subroutine to create a CommandButton on the screen 
SUB MakeACommandButton 		
   ADDOBJECT "CommandButton","MyCommandButton",50,75,100,50   ' create a CommandButton named MyCommandButton 
END SUB  

' A SUB to handle a DblClick Event (a DblClick event handler) for the ListBox called "MyListBox" 
SUB MyListBox_DblClick 		
   MyListBox.Hide ' Hide MyListBox 
END SUB  

' A SUB to handle a Click Event (a Click event handler) for the CommandButton called "MyCommandButton" 
SUB MyComandButton_Click 		
   MyListBox.Show  ' Show the ListBox "MyListBox" when the user clicks "MyCommandButton" 
END SUB  

' Our main routine where the main things happen...good to always have one 
SUB Main 		
   MakeAListBox         ' create a ListBox   
   MakeACommandButton   ' create a CommandButton 
END SUB  Main ' our one and only Immediate command for this program to run the Main SUB 
'---end code here---

The new code consists of the MakeACommandButton and MyCommandButton_Click subroutines, plus the MakeACommandButton line in the Main subroutine.

The points to remember from last article are:

  1. Call Methods using the name of the object, a period, and the name of the Method: MyListBox.Show
  2. Write event handlers using the name of the object, an underscore, and the name of the Method (event to be handled): MyListBox_DblClick

Now this looks like a lot of code (believe me it isn't) and complicated (again it isn't). If you followed the last article this should all make sense, if not reread the last article or email me with questions (Serg@VisualNewt.com).

The one question you may be asking, is why do we use a DblClick (double-click) for the list box, instead of a Click as in the CommandButton? Apart from letting you use more than one type of Method and event handler, the ListBox only responds to single clicks (Click) if there is something in the listbox to click on. Otherwise it only responds to DblClick events. (We'll talk more about Events in the next article).

Now for the simplification (believe me it is). Look at the Main subroutine. It calls two subroutines which "make" or "setup" things. Specifically, the methods set up parts of the user interface. What we can do is factor (like in math...remove the common bits) that code out into a separate subroutine, and replace it with a single call to a subroutine in Main. Like this:

SUB Main 		
   SetupUI  ' call a routine to setup our User Interface 
END SUB

So we replaced two lines of code (which did similar things...namely setting up parts of the User Interface) with a single line of code. That's simplified it. But what is this thing called "SetupUI"? It's a call to a new method we write using the lines we took out! Like this:

'   A subroutine to set up all the bits of our user interface (controls). 
SUB SetupUI 	
   MakeAListBox  ' create a ListBox 	
   MakeACommandButton ' create a CommandButton	 
END SUB 
 So our new (simplified) program now looks like: 
 
'---start code here--- 
' 
' A simple program that creates a ListBox and lets us show and hide it by clicking on it 
' 
' A subroutine to create a ListBox on the screen 
SUB MakeAListBox
   ADDOBJECT "ListBox","MyListBox",50,50,100,100 ' create an empty ListBox 	 
END SUB 

' A subroutine to create a CommandButton on the screen          
SUB MakeACommandButton 	
    ADDOBJECT "CommandButton","MyCommandButton",50,75,100,50 ' create a CommandButton named MyCommandButton  
END SUB   

' A SUB to handle a DblClick Event (a DblClick event handler) for the ListBox called "MyListBox" 
SUB MyListBox_DblClick 	
   MyListBox.Hide ' Hide MyListBox 		
END SUB  

' A SUB to handle a Click Event (a Click event handler) for the CommandButton called "MyCommandButton" 
SUB MyComandButton_Click 	
   MyListBox.Show  ' Show the ListBox "MyListBox" when the user clicks "MyCommandButton" 	
END SUB   

'   A subroutine to set up all the bits of our user interface (controls). 
SUB SetupU
       MakeAListBox  		' create a ListBox
       MakeACommandButton ' create a CommandButton 
    END SUB   

    ' Our main routine where the main things happen...good to always have one 
    SUB Main 	
       SetupUI   ' set up our controls 		
END SUB  Main ' our one and only Immediate command for this program to run the Main SUB 
'---end code here---

You may be shaking your head at this point, totally confused. How is this simpler? Right now, it looks like we've added more code and made things more complex. True we've added more code. It's false that it's more complex. The code is easier to follow, easier to understand, we know now that those two lines that we "factored out" set up our user interface, because our Main now tells us that it does. (SetupUI tells you exactly what those lines do, whereas the individual lines may be doing something else such as modifying the user interface, instead of just setting it up). Also, this is a very simple program, as you write more complex programs, you'll be putting all sorts of stuff into your Main subroutine, which would confuse any other reader (and you) about what exactly those line do.

Factoring is a common computer programming concept. It tries to replace code with a common function, with a single subroutine (or function) call, to make the code more understandable. The other reason for factoring is that it makes the factored lines (those two lines in our example) reusable. If you ever needed to set up your user interface more than once in the program you'd only have to write:

...
SetupUI
...
SetupUI
....

instead of:

...
MakeAListBox  ' create a ListBox
MakeACommandButton ' create a CommandButton
...
MakeAListBox  ' create a ListBox
MakeACommandButton ' create a CommandButton
....

Which you have to admit is a lot less typing. Factoring is a "good thing", to steal a phrase. Byte-sized chunks are easier to digest than pages of commands.

Ok...our little program doesn't do much and it really looks kind of pitiful. Our list is empty and our button looks kind of drab and not really like a button. We're going to change our program (it'll still be pitiful, but it won't look as drab.) keeping all we've gone over in mind.

CommandButtons

The CommandButton we've used is one of the two user interface controls (commonly known as widgets) you'll use most frequently. We'll start our in-depth tour of widgets with the CommandBox, and go right into the other most frequentlyused widget, the MSGBOX.

Referring to the NSBasic manual (and proven by our little program earlier), you create a CommandButton the same way you created the ListBox. The only difference in the command was that "CommandButton" followed the key word ADDOBJECT instead of "ListBox". So, from this we can see that NSBasic has a nice consistent way of creating objects. They all follow the same pattern:

ADDOBJECT "the type of object","the name you give your object", xpos, ypos, width,height

Some objects require all these pieces (such as CommandButton) while others only require some of them, but basically if you know how to create one object you know them all. The differences lie in the Events, Methods, and Properties of each object.

A CommandButton, is a simple button, that the user clicks on to get something to happen. It has some text (a label) that describes what the button does. You can change its colors and the style of the text in the label. It's a fairly simple, but very flexible object.

One thing you should be aware of is that if you look at the CommandButton page of the manual, the Properties, Methods, and Events section of the page refer you to other pages. These pages describe each of the corresponding items, and the values that you can set them to. For instance, the BackColor of a CommandButton (the color of the background--that is, the button face color) can be set to a Color...which in turn is explained on yet another page. After a while you'll remember what goes with what thing. But at first, you'll have to do a fair amount of cross-referencing. Just look up the pages Properties, Events, or Methods as needed.

Ok, back to CommandButtons. Let's give our CommandButton in our example program a title. How do we do this? Well, a CommandButton has a Property (remember this is a characteristic of the object) called Caption. And let's make the button say "Hello" on its face. Again, we refer to properties using the dot "." notation. So we would write:

MyCommandButton.Caption = "Hello"

(Remember to put words that are visible to the user, like the caption in quotes--"Hello" instead of Hello.)

Where do we put this line? Well, it's part of creating our button so put it in the bit of code that creates our button, namely "MakeACommandButton"

' A subroutine to create a CommandButton on the screen 
SUB MakeACommandButton 	
   ADDOBJECT "CommandButton","MyCommandButton",50,75,100,50   ' create a CommandButton named MyCommandButton 	MyCommandButton.Caption = "Hello" 
END SUB

Make this change to your program and rerun it. Your button now has as caption! It looks much more like a real button now. We can make the text in the caption standout, by using the FontBold property. (A Font in computer-talk is the shape of the family of letters or text being used to write with. That is, the shape when you ignore things like underlines, italics, and bold, etc.) When you cross-reference FontBold you find it's set to True/False (something known as a Boolean in computerspeak). So if we set it to True, then the text in the caption should be highlighted. Add the line to MakeACommandButton again. I'll wait for you to do it....back? Good. This is what the line looks like:

MyCommandButton.FontBold = True

When you rerun the program you see the caption is darker and stands out now. Take some time now, and play with all the other Properties of a CommandButton. Try different values for them to see their effect on your single button. A lot of these Properties are common to other objects, so if you experiment with them on the CommandButton, you'll know what they do and how to use them in other Objects.

For the time being ignore Properties labelled as (read-only) in the manual. We don't have enough programming yet under our belts to deal with read-only properties.

Onward!

A CommandButton only handles two Events (Methods you can call): Click and GotFocus. We've seen and worked with Click already; this is the Event that triggers your Click event handler method. GotFocus is a bit harder to explain. In simplest terms, GotFocus means the object has been selected (not clicked) but selected. Typically, you move the focus (selection) around by using the Tab button on the keyboard. It moves the selection (highlighting) around from object to object as you hit Tab. You can then hit the Enter key (or the Casio's Action Wheel) to generate a "click" event on that button or control that has "GotFocus". What the GotFocus event handler lets you do, is let you execute some commands whenever the object (CommandButton in this case) gets highlighted. For instance, maybe you have a message come up like a tool-tip (help bubble) whenever someone selects or highlights your button. You could do that in your GotFocus event handler (since NSBasic doesn't support tooltips).

CommandButton Methods include two that we've played with already: Hide and Show. In addition there is something called "SetFocus" you can call this method (MyCommandButton.SetFocus) to highlight the button (and consequently generate a GotFocus event, which would cause your MyCommandButton_GotFocus method to run.) Phew! Now we see some of the power of Objects! Some methods can create secondary events: Doing a SetFocus causes a GotFocus event to be created which causes your GotFocus event handler (method/subroutine) to run. Take a deep breath and reread what we've done so far. It's a lot to digest, and once you understand (or at least feel comfortable with) all this, you're on the road to being a programmer!

The last metthod a CommandButton deals with is Move. This lets you Move the button from your program--that is, alter where it sits depending on something else. Lets move our button to the right 5 units each time the user taps (Clicks) on it. Cross-referencing Move we see it takes similar values to the actual creation command...so in essence we're reacreating our button somewhere else on the screen. This should be simple then, and it is, but we haven't gone over a crucial part of programming yet, namely something known as "parameters" or "parameter passing". We'll leave this for another time.

That's all there really is to CommandButtons (and lots of other Objects) in NSBasic.

To get you used to using CommandButtons, I want you to write a program for next time.

The program should have:

  1. Four command buttons.
  2. Each button should have a different label: Bold, Italic, Underline, and Normal

The program should:

  1. Start with all captions in the default style (not Bold, Underlined, or Italic)
  2. When you hit the button that says "Bold" the label style should go bold (stand out)
  3. When you hit the button that says "Italic" the label style should switch to italics
  4. When you hit the button that says "Underline" the label style should underline
  5. When you hit the button that says "Nomal" all label styles should go normal (the default) and undo everything else.
  6. No button should affect any other button except for the "Normal" button which affects all the others.
  7. Use factoring.

It's not that hard really. Take is slow and if you get stuck reread the sections of the article that explain what you're stuck on. Check for typos, and use double-quotes! We'll go over the answer next time, and we'll finally explain what a SUBroutine really is, and get our first explanation and use of FUNCTIONs. We'll also go over our next Object, the MSGBOX.

If you get stuck or have a question about anything we've gone over, feel free to email me at Serg@VisualNewt.com

Cheers!

nsblogo2

ARTICLE 5--MSGBOXes, SUB and FUNCTION

Programming Using NSBasicCE

ARTICLE 5--MSGBOXes, SUB and FUNCTION

All content (c)1999, 2002 Serg Koren.

All rights reserved.

Welcome to the fifth installment of NSBasicCE.

This time we go over the another very common user-interface object you will use: MSGBOX.

Leftovers from Last Time

Last time we talked about CommandButtons and I asked you to write a program:

The program should have:

  1. Four command buttons.
  2. Each button should have a different label: Bold, Italic, Underline, and Normal

The program should:

  1. Start with all captions in the default style (not Bold, Underlined, or Italic)
  2. When you hit the button that says "Bold" the label style should go bold (stand out)
  3. When you hit the button that says "Italic" the label style should switch to italics
  4. When you hit the button that says "Underline" the label style should underline
  5. When you hit the button that says "Normal" all label styles should go normal (the default) and undo everything else.
  6. No button should affect any other button except for the "Normal" button which affects all the others.
  7. Use factoring.

If you're just starting out programming you may be overwhelmed by the amount of stuff you have to worry about all at once...don't worry! You don't have to worry about it all at once. Take one item and get is working. Then take another. And so on. This is the principle of divide-and-conquer. For instance, get just the Bold button working properly. Then copy the code from the Bold button and just change the lines you have to to get the Italic button working. And so on. This is mental factoring (as opposed to code factoring which we discussed earlier.) Never get overwhelmed by programming. It always just comes down to solving a tiny little problem and then adding on to it once its solved.

The hardest part of this assignment is the Normal button. The other three buttons just send a message to themselves; the Normal button sends a message to each of the other three buttons.

Here's my version of the program. First you'll notice that it doesn't look anything like yours. This doesn't mean mine is right and yours is wrong. If your program does what the assignment states, then you did it correctly. The most notable difference is probably the coordinates and size you used for the buttons (the last 4 parameters to the ADDOBJECT command). The other differences are due to something known as coding (programming) style. Religious wars have been fought over this and much blood has been shed. Coding style refers to how your code looks on the page. How pleasing to the eye is it. It also refers to how easy your code is to read and understand. Style amounts to how you space your lines, are your keywords (commands) in uppercase, lowercase, mixed case, do you have comments and how are they aligned, etc.

Of course, my coding style is the correct one.

'---start code here--- 
' 
'  A program that demonstrates the Font style capabilities of the CommandButton Object 
' -- Subroutines to create our buttons --- 
' A subroutine to create the Bold button 
SUB MakeBoldButton 	
   ADDOBJECT "CommandButton","MyBoldButton",10,10,70,30   	
   MyBoldButton.Caption = "Bold"   ' set the caption on the button to read "Bold" 
END SUB  

' A subroutine to create an Italic button 
SUB MakeItalicButton 	
   ADDOBJECT "CommandButton","MyItalicButton",10,50,70,30   	
   MyItalicButton.Caption = "Italic"  ' set the caption on the button to read "Italic" 
END SUB  

' A subroutine to create an Underline button 
SUB MakeUnderlineButton 	
   ADDOBJECT "CommandButton","MyUnderlineButton",10,90,70,30   	
   MyUnderlineButton.Caption = "Underline"  ' set the caption on the button to read "Underline" 
END SUB  

' A subroutine to create a Normal button 
SUB MakeNormalButton 	
   ADDOBJECT "CommandButton","MyNormalButton",10,130,100,30 
   MyNormalButton.Caption = "Norlaml"  ' set the caption on the button to read "Normal" 
END SUB 

 ' --- The Click event handler subroutines for our buttons ---
 ' The Bold Click Event handler 
SUB MyBoldButton_Click 	
   MyBoldButton.FontBold = True   ' make the caption bold 
END SUB  

' The Italic Click Event handler 
SUB MyItalicButton_Click   	
   MyItalicButton.FontItalic = True    ' make the caption italic 
END SUB  

' The Underline Click Event handler 
SUB MyUnderlineButton_Click   	
   MyUnderlineButton.FontUnderline = True   ' underline the caption 
END SUB  

' The Normal Click Event handler sends a message to the other 3 buttons 
SUB MyNormalButton_Click  	
   MyBoldButton.FontBold = False          ' turn bold style off