Programming the Palm with NS Basic

By William LaMartin, Editor, Tampa PC Users Group
lamartin@tampabay.rr.com


In the July 2000 newsletter I wrote about my Handspring Visor (think Palm handheld). Online the article is at http://www.tpcug.org/newsletter/nl_2000/july2000/visor.htm. And at the July 2000 meeting, I gave a presentation on the Palm/Handspring handheld devices. Part of the presentation was a demonstration of the Palm Operating System Emulator (POSE), a program that runs on a PC giving you a Palm looking interface where you can run and test programs for the Palm OS.

The real use of POSE is in testing programs one has written for the Palm. At that time I had discovered a little program called PDA Toolbox that allowed you to do simple programming for the Palm without really writing any code—just selecting objects and setting their properties. No real calculations were possible.

Now a year later I have revived my interest in Palm programming with the discovery of NS Basic, an Integrated Programming Environment (IDE). The IDE is displayed on this page. It looks a bit like the Visual Basic or Delphi IDE. You have a collection of objects, like a text field on the left that you can place on the form in the center. You then can right click on the object and set various properties for the object. On the right is a listing of all the objects in the project displayed in the Project Explorer.

The project in the picture has three forms. The form being displayed is the Main form, which contains four buttons and a large text field.

For each of the buttons, I have written code using a scripting language that is very like BASIC. If you remember any version of BASIC, you will be right at home with NS Basic.

ns_basic.jpg (138348 bytes)

The list of objects, statements, and functions is:

Abs, Acos, Acosh, AddDays, AddMonths, AddYears, Alert, AppLaunch, Asc, Asin, Asinh, Atan, Atan2, Atanh, Beep, Bitmap, Button, Call, Ceiling, Chain, CheckBox, Chr, Cos, Cosh, CreateWindow, Cursor, DateVal, DateMMDDYY, Day, DayOfWeek, DayOfYear, DbClose, DbCreate, DbDelete, DbErase, DbFind, DbGet, DbGetNoRecs, DbInsert, DbOpen, DbPosition, DbPut, DbRead, DbReadNext, DbReadPrev, DbReset, DbUpdate, Define, DegToRadians, Delay, DestroyWindow, Dim, Display, Do / Loop, DrawBitmap, DrawChars, DrawLine, DrawRectangle, End Function, End Sub, End Type, End If EraseWindow, Exit Do, Exit For, Exit Function, Exit Sub, Exp, Field, FillRectangle, FirstOfMonth , Floor, For, Format, Function, Gadget, GetEventType, GetKey, GetPen, Global, Gosub, Goto, Hour, HourMin, HourMinAMPM, If /Then/ Else / EndInStr, Int, Label, Label, LastOfMonth, LCase, Left, LeftPad, Len, Let, List, LoadLibrary, Log, Log10, LTrim, MenuDraw, MenuErase, MenuReset, Methods, Mid, Minute, MMDDYYToDate, Mod, Month, MonthDay, MsgBox, Next, NextForm, NoOccurs, Now, PopUp, PopupDate, PopupTime, Pow, Power10, Proper, PushButton, RadToDegrees, Rand, Redraw, Rem, Repeater, Return, Right, RightPad, Round, RTrim, Scrollbar, Second, Select Case / Case / Selector, SerialClose, SerialDial, SerialHangup, SerialOpen, SerialReceive, SerialSend, SerialSet, SetCurrentWindow SetEventHandled, Shift Indicator, Sign, Sin, Sinh, Sound, Sqrt, Stop, Str, Sub, SubtractDays, SubtractMonths, SubtractYears, SysEventAvailable, SysInfo, SysTrapFunc, SysTrapSub, Tan, Tanh, TestNum, TimeVal, ToDate, Today, ToTime, Trim, Trunc, Type, Ucase, Val, Year, YearMonth,

So, you see, that there is a lot of power here.

To use the mathematical functions above, you will need to load the MathLib.prc (50 KB) into your Palm along with the program you have created. Additionally, all programs created with NS Basic require that the NSBRuntime.prc be loaded into the Palm device. The NSBRuntime.prc file is 86 KB, so any program you write will have that much overhead. However, you only have to load it once no matter how many programs created with NS Basic you load. This is similar to the overhead of the Visual Basic runtime files that are required in the Windows environment when you want to run a program created in Visual Basic.

I have only had the program a few days but have basically figured most everything out. Of course, I already know BASIC and have been programming in Visual Basic. Additionally I had already used POSE to test the much simpler programs I created last year with PDA Toolbox.

A Word of warning. If you want to work with Palm databases using NS Basic, you will probably want to take a table you have in a regular database like Microsoft Access and convert it to a Palm database. NS Basic doesn’t have a utility to do this for you, but one can be had at a Yahoo group for NS Basic users.

With trepidation I went to Yahoo, created a profile or whatever is necessary to get a Yahoo email address, and signed on to the NS Basic group, http://groups.yahoo.com/group/nsbasic-palm. I say with trepidation because at one point a good portion of the junk email I received came from Yahoo addresses. That has subsided in recent months. The group is a good source of information on NS Basic and of Palm programs created with it that can be downloaded and studied. Based on messages there, it appears that people are using NS Basic to create significant programs used by their companies in a commercial environment.

I have now created two similar Palm programs and two associated Palm databases that display name, address, telephone number, etc. for a group of individuals and allow searches by name or address. One is for the members of the Tampa PC Users Group, and the other is for my neighborhood association. That shows I have figured out non-keyed database access on the Palm using NS Basic.

Next I recreated a couple of programs I had written in our Visual Basic SIG as demonstrations, one using financial calculations, the other using trigonometric calculations to solve a standard surveying problem that member Mike Hutchison introduced to us. Here is what the second program looks like running on the Palm Emulator (it has a Handspring Visor skin). The program has a second screen where a graph of what is being surveyed is displayed.

bearing_traverse_1.jpg (44808 bytes)

I was basically able to drop the Visual Basic code into NS Basic, make a few changes and have a functioning program—until I tried to do the drawing. The problem I had with that was in positioning and scaling the drawing on the screen. Theoretically it should be no more difficult than in Visual Basic, but for me it was.

I also had trouble with the scope of variables I declare, and to make things work I ended up with a lot of global variables. This is slightly different from Visual Basic.

A full working demonstration copy of NS Basic can be downloaded by a link on the page http://www.nsbasic.com/palm/info/faq.html. The exact link is http://www.nsbasic.com/pub/Palm_files/updates/NsbasicDemo.exe. The only restriction is that it is good for 30 days and any applications you create will only work for five days. Of course, you may recompile them, and they will work for another five days. The program costs $99. The general web site is http://www.nsbasic.com/.

If you would also like to investigate the competition, here are three links:

AppForge ($299) http://www.appforge.com/

CASL ($65) http://www.caslsoft.com

PDA Toolbox ($25) http://www.pdatoolbox.com/

All, I believe, have free demo versions. u