Tech Note 19: NS Basic Introduction for VB6 Users

May 01, 2008


(Contributed by Paul Abell)

This document is being written in an effort to help VB6 programmers learn NSBasic. Maybe it will help you ease into it a little faster than I did.

For starters, it is almost a no-brainer. In fact, NSBasic looks almost identical to VB6 at first startup and works almost the same way. What are the differences then?

You will be familiar with all the controls and buttons, properties, double clicking, etc. What you will be confused by is where you put your code. This is caused by the device not being the same as Windows. It is programmed differently and has a few differences in the way you access different parts of the operating system.

If you double click on the form to bring up the code as in VB6, you will be surprised to get nothing, no response. HereÕs how you have to do it. Click on menu item, ÒProjectÓ, and select, ÒStartup CodeÓ. Now you will be on your home turf again, familiar ground. The ÒStartup codeÓ section is run on program startup and is run first. The ÒTermination codeÓ is run last, when your program stops or another application menu button is tapped. The button, label, field, gadget, bitmap, popup, etc codes are where you expect them to be. Just double click on them. There are four more places to put code and each one has its own reason for being as you will see when you start to program. Right click on the form and you will get a menu with three code sections on it. ÒBefore codeÓ, ÒAfter codeÓ and ÒEvent codeÓ. The last code section is the ÒcodÓ module and can be used for any code you want to put in it. To access it, select menu item ÒProjectÓ and select ÒAdd New ModuleÓ. Add your code to it. To access it again, after closing the form, you will have to go to the project explorer window and double click on the ÒModulesÓ menu item. Select the cod module you want by double clicking on it. (NOTE: Be sure to add this module to your list, whenever sending your project to another user!)

Now to the ÒBeforeÓ code module. This code module is run before the form is created. The ÒAfterÓ code module is run after the form is created and is where the controls are painted on, etc. It is important to note that it is run every time the form is accessed. If you do something on the form and then go to another form, when you come back to that form its ÒAfterÓ code is run again. The ÒEvents code module is special and is used to trap the user pressing any of the buttons on the device, usually the menu or applications buttons. Also the scroll up and down buttons, etc. Any time an ÒeventÓ occurs this module runs.

There is no debug option. Since the IDE runs on the desktop and the app is running on a separate device, there is no practical way for the IDE to get the hooks into the app that would be needed to debug.

The output file from NS Basic is complete with all your code, forms, etc. in one nice neat file. You can install it to your device with one touch. If you happen to reference any external libraries in your code you will have to supply that library also with your program. You can do almost anything without having to access external libraries, but they are available.

NS Basic does have some nice touches that mimic VB6 almost identically. You will feel right at home. It has some unique features that are much easier to use than VB6 I think, such as, popup lists and date and time selectors. You do not have much control over your buttons, just basic size, bold, hide and so on. Also, there is very little color support. You can use color graphics up to 8 bits, or 256 colors.

There are some programming items you donÕt find out about immediately or at all with the demo version.

  1. Line continuation characters. use the underscore at the end of a line.
  2. To make your program stop and return control back to the program launcher, like it was before you selected it, use the STOP code word. If you use EXIT, your program will just sit there and stare at you until you select another application button.
  3. Files are really very simple, but you have to know a couple of their idiosyncrasies. If a file doesnÕt exist you have to create it. Makes sense doesnÕt it. But what they donÕt tell you is, you also have to open it after you create it! That can cause you a lot of trouble. Most of the error messages are rather cryptic and not simple and straightforward. DonÕt blame NS Basic for that. Comes from the environment.
  4. Although your completed, compiled program will contain everything needed, if you upload or transfer your project files to another user, be sure to include any cod files associated with it, including bitmaps, icons, etc.

One last item I will mention, that will get you up and running almost without any help, is bitmaps or graphics. This includes icons. NS Basic has a unique way of accessing bitmaps and it is not drop and drag; that you will miss! Yes, you do drag and drop the bitmap object, but it is just an object and not the bitmap itself as with VB6. To use any bitmap on NS Basic you have to first access the ÒProjectÓ menu and select ÒAdd bitmapÓ. This lets you pick it out as you would from VB6. This process adds it to the project explorer menu. To use the bitmap you just loaded, go to the project explorer menu and double click on ÒBitmapsÓ. Select the bitmap you loaded and it will bring up the properties window for that bitmap. You will notice it has room for four entries, each a different level of color depth. One bit, through 8 bits. The one bit entry is filled with your bitmaps location. Select the other bitmap color depth levels one at a time and enter the same bitmap name and location until all bitmap color depths have been filled identically. Now you can actually use them! Here's how: Go to the bitmap object on your form and click on it. Now on itÕs property menu select, ÒResource IDÓ, and type in the bitmap ID number that was assigned to your bitmap when it was loaded. ThatÕs all there is to it! A little involved, but simple enough when you get the hang of it. Fortunately, NS Basic has made it simple, in the respect that you donÕt have to be too particular about the bitmap file type. It will accept a wide range of common bitmap file types. These are converted automatically at compile time. Icons have to be small, 22x22 or 15x9 pixels, and bitmaps can be up to 160x160 pixels.

This should be enough to get you started. You will love how easy it is to use. It is very good about checking for errors before you try to load it. You will come to appreciate that believe me. NS Basic has its own set of little peccadilloes, but donÕt all language compilers? TheyÕre working on that.

Got more suggestions to help VB6 users come up to speed? Send them to us at support© nsbasic.com