Short Tutorial for HotPaw(tm) Basic for the PalmOS (formerly cbasPad Pro Basic) Installation: Install the usual way, using the 3Com/Palm Install and HotSync utilities on a Windows or MacOS based PC, or using the linux pilot-xfer utility on a computer running linux or unix. You can have both HotPaw cbasPad Pro Basic and cbasPad 0.9x installed on your PalmPilot at the same time; however cbasPad classic should be installed and run first if you want to share the scratchpad. Installing HotPaw Basic programs: Basic programs are text files or memos containing statements in the Basic language. The HotPaw Basic application can run Basic programs whose text is contained in memos of the built-in Palm MemoPad. If you have a HotPaw compatible Basic program on your desktop PC, you can copy and paste the Basic program text into the Desktop MemoPad application and HotSync. On a linux system, you can use the pilot-link install-memo utility to copy a short text file into your Palm MemoPad. Getting Started: Try entering a short Basic program into your Palm MemoPad. Start a new memo (in any category). Any memo starting with the '#' character and ending with the 4 characters ".bas" in the first line will be recognized as a Basic program in the HotPaw Basic Show Programs selection screen. Here's an example first line: # My Example 1 .bas Here's a short test program that will ask you to guess a number: #guess_a_number.bas x = 0 # set the variable "secret" to a number between 1 and 5 secret = 1 + rnd(5) while (x <> secret) input "Guess a number between 1 and 5", x wend display x; " is correct!" end Switch to the Basic application. If there is not a border around a list of programs, use the menubar to select "Show Programs". If you can't see your new program, check the name to make sure it starts with a # and ends with .bas on the first line. Select your program and hit the "Exec" button to execute it. If you use the Hackmaster extension utility, then try using the SwitchHack extension to switch back and forth between Basic to the MemoPad application when writing and testing your Basic programs. The "Show ScratchPad" is for small calculations that do not require any loops or subroutines. Just enter a list of equations and a print statement for the result, then the statements you wish executed, and hit the "Exec" button. Some one line examples: x = 7 y = x + 3 xsquared = x ^ 2 # this is a comment line (because of the leading '#'). # multiple statements per line allowed. x = 7 : y = 3 + 4 # a print or "?" statement prints 1 line to a dialog box: print "hello", "world" ? 23+7 , 23-7 print x # an inputbox statement gets one line from the user: n$ = inputbox("Enter your name:") print "your name is ", n$ input "Enter an integer number:"), x print "The next integer is", x+1 *********************************************************************** More Examples *********************************************************************** Cut and paste these examples into the desktop MemoPad, and then perform a HotSync operation to install them onto your Palm handheld. You can the use the MemoPad application on your Palm to double check the transfer. Make sure the very first character in the Memo is a # Make sure the last 4 characters of the first line are .bas with no trailing spaces. These examples should then show up in the HotPaw Basic "Show Programs" display. Example 1a: Hello World -- -- cut here -- -- #first_example.bas # enter this into the MemoPad and start yBasic # prints "Hello World" # a$ = "Hello" b$ = "World" print a$, b$ end -- -- cut here -- -- Example 1b: LOOP AND PRINT -- -- cut here -- -- # example 1 .bas # prints a small "TIMES THREE" multiplication table # for i=1 to 4 print 3 * i, next i print end -- -- cut here -- -- Example 2a: INPUT AND DISPLAY (left blank...) Example 2b: Writing to the MemoPad -- #memopad table .bas open new "memo","trig table 1" as #4 m = db.index :' memo number for d = 0 to 180 step 15 r = fn rad(d) print #4, d,sin(r),cos(r) next d close #4 end -- Example 2c: MemoPad read -- #memopad table .bas m = db.find("memo","trig table") if (m < 0) then end :' not found open "memo",m as #1 input #1,title$ :' skip title input #1,a$ while not eof :' check for end display a$ input #1,a$ wend close #1 end -- Example 3: FINANCIAL CALCULATION -- -- cut here -- -- # loan payment .bas # calculates loan payments n$="" for i=0 to 17: s$(i)="": next i s$(0)="by "+n$ s$(2)="Principal" s$(4)="Years" s$(6)="Interest %" s$(8)="Periods/Yr": s$(9)=12 while (1) j = form(12,0,"Payment Calc") if j=0 then end i=(val(s$(7))/100)/val(s$(9)) p=val(s$(3)) n=12*val(s$(5)) a=fn pmt(p,i,n) a$=str$(a,5,2) s$(10)="Payment" s$(11)="$"+a$ wend end -- -- cut here -- -- Example 4: GRAPHICS -- -- cut here -- -- # circle demo .bas draw -1 :' clear screen cx = 80 : cy = 80 :' set center r = 30 :' set radius moveto cx+r,cy for a = 0 to 6.28 step 0.1 x = cos(a) y = sin(a) lineto cx+r*x, cx-r*y next a w = fn pen(0) :' wait for tap end -- -- cut here -- -- Example 5: DATABASE -- -- cut here -- -- # db new+find .bas # create a new DB database # fill it with 5 records # and search for 1 item f$ = "test-db-1" mydb=open f$ as new "DBOS",4 if mydb<0 then end d=fn days(fn date$(0)) for i=0 to 5 # make up some fields s$(20)=chr$(asc("A")+i) +"2" s$(21)=right$(fn date$(d+i),4) s$(23)="00" + str$( i) s$(22)=str$(timer) put mydb,i,104 next i # now find a record j=db.find(f$,"C") if j >= 0 then rem # get 2nd field a$=get$(mydb,j,2) endif # display found item ? j,a$ end -- -- cut here -- -- Example 6: SCRIPTING PALM APPS Example 6a: find appointments -- -- cut here -- -- # datebook today .bas # find todays DateBook items d=val(fn date$(0)) k=find("date",0,d) while (k >= 0) if k < 0 then end a$ = get$("date",k,10) ? k,a$ k=find("date",-12,d) wend end -- -- cut here -- -- Example 6b: -- -- cut here -- -- # count done todos .bas # counts up items in your ToDo list c=db.len("ToDoDB") n=0 # count only priority 2 p=2 : p$=str$(p) for i=0 to c-1 get$("todo",i,10) draw str$(i),80,80 # count only done todos if s$(25) = "1" and s$(24) = p$ n=n+1 endif next i ? n," done todos with priority ", p end -- -- cut here -- -- Example 6c: -- -- cut here -- -- # todo today .bas # find ToDos due today k=0 k=find("todo", -11, val(fn date$(0)) ) 30: if k<0 then end a$=get$("todo",k,10) if s$(25)="0" then ? k, a$ # ? "+",k,a$,s$(25) k=find("todo", -12, val(fn date$(0)) ) goto 30 end -- -- cut here -- -- Example 6d: # put todays due ToDos into Datebook (left blank...) Example 7: Put Appointments in ToDo list -- -- cut here -- -- #datebook2todo.bas # HotPaw Basic ( cbasPad Pro ) program # to make new ToDo's # from todays appointments. t$="make new ToDo ?" d=val(fn date$(0)) :' today date k=find("date",0,d) :' find 1st while (k >= 0) :' anything? a$ = get$("date",k,10) :' get it s$(24) = 5 :' priority 5 s$(25) = 0 :' not complete s$(26) = 0 :' unfiled s$(27) = "" s$(29) = "" :' no note y = msgbox(a$,t$,2) if (y = 1) put "todo",new,10 :' make todo endif k=find("date",-12,d) :' find next wend msgbox( "done") end -- -- cut here -- -- Example 8: SERIAL PORT I/O -- -- cut here -- -- # serial port I/O # emulates a 1 line terminal # at 19200 baud open "com1:",19200 as #5 a$="" k$=inkey$ while asc(k$) <> 12 # use the scroll down button to exit if len(k$) > 0 rem # send graffiti out serial port print #5,k$; if asc(k$) = 10 print #5, chr$(13); endif endif # check for serial input s = fn serial(5) if s > 0 then a$ = a$ + get$(#5,s) rem # display input draw a$+" ",10,90 if len(a$) > 32 then a$="" endif k$=inkey$ wend close #5 end -- -- cut here -- -- Example 9: dynamic button -- -- cut here -- -- # mybutton.bas draw -1 form btn 60,80,40,12, "DoIt",1 form fld 60,120,80,12, "Nobody",1 draw "Enter your name",60,100 x = asc(input$(1)) :' wait for button ? "Your name is ",s$(0);"." end -- -- cut here -- -- Example 10: BENCHMARK -- -- cut here -- -- # sieve.bas # prime number sieve benchmark # from Byte magazine 1984 new 20 t = timer(100) 25 s = 8192 : rem full size 30 dim f%(s+2) 40 for i = 0 to s-1 : f%(i) = 1 : next i 50 c=0 60 for i = 0 to s-1 70 if f%(i) = 0 then 110 80 p = i+i+3 : if i+p > s then 100 90 for k = i+p to s step p : f%(k) = 0 : next k 100 c = c+1 110 next i 120 ? c ; " primes found in " ; 130 t =(timer(100))-t : t=t/100 140 ? t ; " seconds" 150 end run -- -- cut here -- -- ********************************************************************** Usage of the Software is subject to the following limitations and disclaimers. WARRANTY AND DISCLAIMER The Software is distributed in the hope that it might be useful, but WITHOUT ANY WARRANTY OF ANY KIND; not even the implied warranties of MERCHANTABILITY, fitness for ANY particular purpose, or for non-infringement of any intellectual property rights. LIMITATION OF LIABILITY UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT, OR OTHERWISE, SHALL HOTPAW, RONALD NICHOLSON, OR ITS SUPPLIERS OR RESELLERS BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES. IN NO EVENT WILL HOTPAW BE LIABLE FOR ANY DAMAGES IN EXCESS OF THE AMOUNT HOTPAW RECEIVED FROM YOU FOR A LICENSE TO THIS SOFTWARE, EVEN IF HOTPAW OR RONALD NICHOLSON SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. FURTHERMORE, SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS LIMITATION AND EXCLUSION MAY NOT APPLY TO YOU. IN THE EVENT THIS SOFTWARE INFRINGES UPON ANY OTHER PARTY'S INTELLECTUAL PROPERTY RIGHTS, THE LICENSOR'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL BE, AT THE LICENSOR'S CHOICE, EITHER (A) RETURN OF THE PRICE PAID TO THE LICENSOR AND ITS AUTHORISED DISTRIBUTORS OR (B) REPLACEMENT OF THE SOFTWARE WITH NON-INFRINGING SOFTWARE. LIMITATION OF HIGH RISK ACTIVITIES The Software is not fault-tolerant and is not designed, manufactured or intended for use or resale as on-line control equipment in hazardous environments requiring fail-safe performance, such as in the operation of nuclear facilities, aircraft navigation or communication systems, air traffic control, direct life support machines, or weapons systems, in which the failure of the Software could lead directly to death, personal injury, or severe physical or environmental damage ("High Risk Activities"). Ronald Nicholson, HotPaw, and its suppliers SPECIFICALLY disclaim ANY express or implied warranty of fitness for High Risk Activities. This license is governed by the laws of the United States and the State of California. If, for any reason, a court of competent jurisdiction finds any provision, or portion thereof, of this license to be unenforceable, the remainder of this license shall continue in full force and effect. AGREEMENT If you do not agree to the terms of this DISCLAIMER, you are not authorized to use the Software. *** This documentation is preliminary and subject to change at any time without notice. -- Palm, PalmOS and HotSync are trademarks of Palm Computing. HotPaw and cbasPad are trademarks of the HotPaw company. Copyright 1999,2000 Ronald H. Nicholson, Jr. rhn@nicholson.com ***