How to Convert Palm™ Memos to To Do Items with HotPaw BASIC

by Ricky Spears
Last Update: June 22, 2004

I recently realized a need to convert items that I had in the plain text format of a Palm Memo to items in the Palm To Do database. I didn't see any programs on the market to do this so I decided to write my own. The information below explains how you can use this program yourself, even if you know nothing about programming. For those users that might want to learn more about programming in HotPaw BASIC on the Palm platform, I have included very well documented source code in the final section

Note: The information supplied in this article is for educational purposes only. Ricky Spears and RS Innovative assumes no risk or responsiblity relating to your ability or inability to use the program below. If you have ideas for enhancing this program or article, or any comments on the program or article, feel free to send me an email (webmaster@rickyspears.com).

The Implements

Several years ago I downloaded and began to play with HotPaw BASIC. I registered the program and wrote some small programs with it that helped me personally but few things that I felt would be of any interest to the rest of the computing world. HotPaw basic was written by Ron Nicholson, a great programmer on many platforms including the Palm OS. His web site can be found at www.hotpaw.com.

HotPaw BASIC is a version of the interpreted BASIC programming language written especially for the Palm OS. Although it can be used for a great number of purposes, I find it most useful as a utility scripting language. It is very easy to write programs that interact with the data in the built-in databases. Programs are written in the Palm Memo Pad, which means that I can program anywhere and don't have to be tied to a desktop IDE.

The Implementation

To use this program yourself, you will need to install HotPaw BASIC on your handheld. This can be downloaded from www.hotpaw.com/rhn/hotpaw/. Even if you never want to program in this language yourself and therefore have no need to register the program, the demo version will allow you to run up to 4 BASIC programs on your handheld for an unlimited period. So if memo2todo is the only thing you will need this for, then it is essentially all free!

Once you have installed HotPaw basic on your device. Paste the following BASIC program into a new memo:

#memo2todo.bas
draw -1
call countmemos
dim f$(mc)
call countcats
dim c$(mxct)
c$(mxct)="Unfiled"
dim p$(5)
for p = 1to 5 : p$(p)=p: next p
call readdir
form btn 90,100,40,12,"import",1
form lst 10,35,mc-1,1,f$,1
for ct = 1 to mxct
cat$= fn todocatname(ct)
c$(ct) = cat$
next ct
c$(mxct)="Unfiled"
form lst 10,65,mxct,1,c$,1
form lst 10,95,5,1,p$,1
print at 1,20
print "Choose memo to import to To Do:"
print at 1,50
print "Choose categor to import to:"
print at 1,80
print "Choose priority:"
x = asc(input$(1))
f2$=f$(val(s$(0)))

open "memo", f2$ as #1
input #1, a2$
while not eof
input #1, a2$
s$(20)=a2$
s$(26) =val(s$(1))
if val(s$(1)) = mxct then s$(26) = ""
s$(24) = val(s$(2))
if a2$<> "" then put "todo", new, 10 :c2 = c2 + 1
wend

print at 1,120
print str$(c2); " new To Do items have been added to "
print c$(val(s$(1))); " category!"

while
wend

sub readdir
er=0 :ix=0: fx=1
while
a$=db$("memo",ix,0)
if a$="error"
er=er+1
else
er=0
endif
if er=100 or fx=mc then exit while
f$(fx)=a$: fx=fx+1: ix=ix+1
wend
end sub

sub countcats
for ct = 1 to 16
cat$= fn todocatname(ct)
if cat$ = "" then mxct=ct: ct=16:
next ct
end sub
end

sub countmemos
mc=1
while a$<>"error" and mc < 75
a$=db$("memo",mc,0)
mc = mc + 1
wend
end sub
end

Note: I'll admit that this isn't a great coding job. The code was written very quickly and was meant to be functional only. This is a caveat of developing on such a small screen. I may clean it up at a later time, or do things more efficiently, I don't know. Other programmers, I don't want to hear it. :o)

Once you have the code in a memo and the HotPaw program installed, follow the below screen shots to see how to use the program.


1) Create a memo with all the lines you want to import. Note that the title line will not be imported, so this can be descriptive. Note: HotPaw basic can only have a total of 100 items in drop-down menus on any form. If you have more than 60 memos on your Palm start the names of the ones you want to import with symbols (like: !!!,@@@, or ###) to move them to the top of the list.

2) Go to the Applications Launcher and tap on the yBasic icon.

3) The HotPaw BASIC interpreter lists all the available programs that are in the Memo Pad. Choose the one that says, #memo2todo.bas and tap the "Run" button.

4) When the program runs you will see three drop-down boxes for your to select various options and an "import" buttton.

5) Choose the memo with the contents that you want to import into the To Do database.

6) Choose the To Do category that you want the imported items to be listed in.

7) Choose the priority that you want the imported To Do items to have.

8) When you have selected all the options, tap on the import button.

9) The program will tell you how many new To Do items heve been aded and to what category they have been added.

10) Go into the To Do list and choose the appropriate category to see that the items have been properly imported.
   

The Instruction Set

If you only want to use this program to import items from the Memo Pad into the To Do database, you can stop reading. However, if you want to find out a little more about how HotPaw BASIC works, here is some heavily commented code. The comments don't appear above because then the program would exceed the 4k limit on Palm Memos.

#memo2todo.bas
# All Hot Paw BASIC programs begin with the "#" comment line and the name of the program
# followed by the .bas extension. This is what the interpreter looks for to identify memos as HotPaw programs.

draw -1 #Clear the screen
call countmemos #First we want to count the number of memos in the database. See the countmemos subroutine for details
                # The total number of memos will be returned in the varialbe mc

dim f$(mc) #f$ is the array variable where we will store all the titles of the memos for the drop-down box
           # We will dimesnion this array just big enough to hold them all

call countcats #We need to count the categories. See the countcats subroutine for details
               # The total number of used categories + 1 for "Unfiled" will be returned in the variable mxct
dim c$(mxct) #c$ is the array variable where we will store the list of To Do categories
c$(mxct)="Unfiled" #"Unfiled doesn't show up in the list, so we have to manually add it to the list.
dim p$(5) #This is the array variable where we will store the priorities
for p = 1 to 5 : p$(p)=p: next p #Store the numbers 1, 2, 3, 4, and 5 in the p$ array
call readdir #Get all the names of the memos into the f$ array
form btn 90,100,40,12,"import",1 #Place a command button on the screen at position X=90, Y=100
                           # The button will be 40 pixels wide and 12 pixels high
                           # The text on the button will say "import"
                           # I'm not exactly sure what the final 1 is for  <:)

                           #Form Buttons should be created before any other form items.
form lst 10,35,mc-1,1,f$,1 #Place the memo list box (drop-down box) at position X=10, Y=35. (0,0 is the top left hand corner)
                           # There will be mc-1 number of items displayed in the list.
                           # We want the first memo to be the initially selected memo, so the next number is 1
                           # Next we tell it the name of the array where it will find all the values to display - f$
                           # I'm not exactly sure what the final 1 is for  <:)

for ct = 1 to mxct #Start a loop counting up to the number of categories
cat$= fn todocatname(ct) #Get the name of the next category by number
c$(ct) = cat$ #Store the next category name in the c$ array
next ct #Continue the loop until we have them all
c$(mxct)="Unfiled" #Since Unfiled doesn't appear, we have to manually add it.
form lst 10,65,mxct,1,c$,1 #Place the category list box (drop-down box) at position X=10, Y=55. (0,0 is the top left hand corner)
                           # There will be mxct items displayed in the list.
                           # We want the first category to be the initially selected memo, so the next number is 1
                           # Next we tell it the name of the array where it will find all the values to display - c$

form lst 10,95,5,1,p$,1 #Place the priority list box (drop-down box) at position X=10, Y=95. (0,0 is the top left hand corner)
                           # There will be 5 items displayed in the list.
                           # We want the first memo to be the initially selected memo, so the next number is 1
                           # Next we tell it the name of the array where it will find all the values to display

print at 1,20 #Set the print position for the next print statement
print "Choose memo to import to To Do:" #Print the instructions for the memo list box
print at 1,50 #Set the print position for the next print statement
print "Choose categor to import to:" #Print the instructions for the category list box
print at 1,80 #Set the print position for the next print statement
print "Choose priority:" #Print the instructions for the priority list box
x = asc(input$(1)) #Wait for the "import" command button to be pressed
f2$=f$(val(s$(0))) #s$(0) holde the index for the item selected in the first list box (memo)

open "memo", f2$ as #1 #We are going to open the chosen memo for reading
input #1, a2$ #We will pull out the first line and ignore it since it is the memo title
while not eof #We are going to loop through to the end of the file and read one line at a time
input #1, a2$ #We read the next line of the memo and store the text for that line in the variable a2$
s$(20)=a2$ #s$(20) holds the description for the To Do item we are about to add (Refer to the HotPaw documentsion for s$() info)
s$(26) =val(s$(1)) #s$(26) holds the category number for the To Do item we are about to add
if val(s$(1)) = mxct then s$(26) = "" #We need to clear out s$(26) if the "Unfiled" category was chosen
s$(24) = val(s$(2)) #s$(24) hold the priority of the To Do we are about to add
if a2$<> "" then put "todo", new, 10 :c2 = c2 + 1 #Check and see if the line is blank.
                                                  #If the line isn't blank, add a new To Do using the
                                                  #  previously defined s$ values
                                                  #Add one to the counter so that we can inform the
                                                  # user how many new To Do items were added
wend #Loop back until we reach the end of the memo

print at 1,120 #Set the print position
print str$(c2); " new To Do items have been added to " #Notify the user how many To Do items were added
print c$(val(s$(1))); " category!" #Notify the user into what category the items were added.

while #Put the program into an infinite loop until the user taps the "Quit" button.
wend  #It's crude, but it works! :o)

sub readdir #This subroutine get's the names of all the memos and puts them in an array
            # I didn't write this routine. It came from a sample program called #dirlist.bas
            # I think it could be much cleaner but I've left it mostly untouched.
er=0 :ix=0: fx=1 #initialize an error counter and a couple of accumulators
while #We are goiing to loop throug the memos until we get to the end.
a$=db$("memo",ix,0) #We will get the title of the next memo and store it in a$
                    # ix is the memo number
                    # 0 is the character position where we will start extracting data
if a$="error" #If the memo doesn't exist, it will return "error"
er=er+1 #count the errors
else
er=0 #otherwise set the error couter to 0
endif
if er=100 or fx=mc then exit while #If we have reached the end or we have had 100 errors then bail out
f$(fx)=a$: fx=fx+1: ix=ix+1 #Add the memo to the array and increment the accumulators
wend
end sub #End of the subroutine

sub countcats #This subroutine will count the number of To Do categories
for ct = 1 to 16 #We know that there won't be more than 16 so we will just count to 16
cat$= fn todocatname(ct) #Get the name of the next category
if cat$ = "" then mxct=ct: ct=16: #If it returns nothing then increment the maximum category variable by one
                                  # also set the counter equal to 16 so we can bail out early
next ct #Are we at 16 yet? If not then keep going...
end sub #end of the subroutine

sub countmemos #This subroutine will count the number of memos in the database
mc=1 #We know that there is at least one or else this program wouldn't be running, so let's start there
while a$<>"error" and mc < 60 #We will loop through until we start getting errors or we get to 60 memos. Then we will stop.
                              #HotPaw Basic only allows 100 total items in the dropdown menus on any one screen
                              #This limits the program to only retrieve the first 60 memos

a$=db$("memo",mc,0) #Get the first line of the next memo
mc = mc + 1 #increment the memocount accumulator
wend #Have we gotten an error yet? If not then go back for more.
end sub #end of the subroutine
end #end of the program. This line must be here!

As I wrote the comments for this code I could see a number of areas that could be very easily cleaned up and made much more efficient and portable. I will likely do this in the future but for now it shows one of the hurdes in coding on the device. When you can only see about 10 lines of code on the screen at once, and you are limited to only 4k, one develops a tendency to get something that will work and then leave it alone. It's just too much work to clean it up.

Overall, I like programming with HotPaw. It reminds me of the days when I first learned to program on an 8-bit Commodore Vic20 with a 22 character wide screen and only 3.5k of RAM. Those were the days...

Copyright © 2004 by Ricky Spears
www.RSInnovative.com

Updates to this article:

June 22, 2004

James Hundley (jhundleyj@yahoo.com) has modified this script with the following features:
   - Only lists memos beginning with a caret (^) so you can keep your lists for import separate from other memos
   - Ability to exclude commented lines from import. Line items that begin with a pound sign (#) will not be added.
   - Ability to include the category within the import file
   - Added a check box to the form to add a datestamp for the day the item was imported

James' code can be found in the Memo2Todo[JH20040622].txt file and a sample input file can be found in the SampleInput[JH20040622].txt file. If you need support for James' changes please contact him directly.

June 21, 2004

It seems that for some users limiting the memos to the first 75 just wasn't enough so I've changed it to the first 60.

Changed line in the countmemos subroutine from:
while a$<>"error" and mc < 75
to
while a$<>"error" and mc < 60

Changed code documentation from:
while a$<>"error" and mc < 75 #We will loop through until we start getting errors or we get to 75 memos. Then we will stop.
                              #HotPaw Basic only allows 100 total items in the dropdown menus on any one screen
                              #This limits the program to only retrieve the first 75 memos
.
to:
while a$<>"error" and mc < 60 #We will loop through until we start getting errors or we get to 60 memos. Then we will stop.
                              #HotPaw Basic only allows 100 total items in the dropdown menus on any one screen
                              #This limits the program to only retrieve the first 60 memos

The following sentence was added to step 1 of the instructions: "Note: HotPaw basic can only have a total of 100 items in drop-down menus on any form. If you have more than 60 memos on your Palm start the names of the ones you want to import with symbols (like: !!!,@@@, or ###) to move them to the top of the list."

May 19, 2004

Changed line in the countmemos subroutine from:
while a$<>"error"
to
while a$<>"error" and mc < 75

Changed code documentation from:
while a$<>"error" and mc < 75 #We will loop through until we start getting errors. Then we will stop.
to:
while a$<>"error" and mc < 75 #We will loop through until we start getting errors or we get to 75 memos. Then we will stop.
                              #HotPaw Basic only allows 100 total items in the dropdown menus on any one screen
                              #This limits the program to only retrieve the first 75 memos

The following sentence was added to step 1 of the instructions: "Note: HotPaw basic can only have a total of 100 items in drop-down menus on any form. If you have more than 75 memos on your Palm start the names of the ones you want to import with symbols (like: !!!,@@@, or ###) to move them to the top of the list."

March 6, 2004

Original article and program published at www.RSInnovative.com