Dr. Dobb's Journal August 2001
Using the Palm Software Developers Kit (SDK) can be a daunting experience. Not only does the SDK require you to know C programming, but it is challenging in terms of new API references and memory management. The AppForge development environment, on the other hand, can help out by leveraging Visual Basic's ease of use.
AppForge (http://www.appforge.com/) was developed as an add-on to the standard Windows version of the Visual Basic 6 Integrated Development Environment (IDE). AppForge is available in a professional edition and a standard edition, which is downloadable for a free 30-day evaluation. AppForge for Visual Basic integrates directly into the Visual Basic IDE as an add-on and consists of three components:
As Figure 1 illustrates, an AppForge program is similar to any application when being developed in the VB IDE except for the extra controls in the Toolbox (the Ingots), which are the size of the form that is created by default. At 160×160 pixels, the size is the same as a standard Palm Pilot screen.
To illustrate AppForge development, I'll present a program that uses a variety of AppForge features, including a database and several AppForge Ingots. Once completed, the program lets you track basic information about job times and signatures for projects that you are working on. You can walk through the development of this project using the 30-day trial version of AppForge.
The only limitation to the functionality is the 30-day time limit. The complete source code and related files are available electronically; see "Resource Center," page 5.
Once you've installed AppForge, start Visual Basic and from the Projects Type window select AppForge Project. You will be presented with a toolbox that has the AppForge Ingots already available along with the standard VB intrinsic controls. The standard VB controls cannot be used in a Palm project, but are displayed in the toolbox. As a reminder, if you try to place a standard control on the form, you are warned by the IDE that you cannot use it. Along with the toolbox, a form is displayed and ready for you to begin working.
Like most VB applications, the first step in the project is to create the basic layout of a GUI. You can begin by placing several AppForge Label Ingots on the 160×160 form that was created when you began the project. When you place the first Ingot on the form, you are asked to save the project before continuing. Save the project in an empty directory of your choice. The directory will also be used later to store the database files. The project needs five Labels with the captions Record, Date, Time, Project Name, and Signature. An additional Label needs to be created to store the record information, and as such, should have its caption changed to a blank space. The GUI should look something like Figure 2.
The next step is to create three Text Box Ingots and set their properties as txtName, txtDate, and txtTime. These Ingots display information contained in a database and should have their captions set to empty space.
One special AppForge Ingot is the Signature Ingot. As its name suggests, it's used for storing information the user draws or writes on the screen. This application uses one of these for a user signature. Place a single Signature Ingot on the form.
Lastly, you need to create six Button Ingots that perform a variety of input options. Create the buttons with the properties in Table 1. The final GUI should look like Figure 3.
The next step is the development of a database on the Windows desktop. Using Access 2000, create a database with the fields in Table 2. After the Access database is completed, save it using the name SigTime.mdb. Next, use the AppForge Database Converter (installed with AppForge) to convert the Access MDB database to a Palm database (PDB). The converter generates the Palm database along with a BAS file that you can use in the VB project. The BAS file contains the entire basic framework for accessing and using the Palm database on the desktop or Palm device, and should be saved to the directory you selected for the project in an earlier step.
With the database and BAS files created and copied to the same directory, begin working on the rest of the program. The first thing to do is to add the BAS file, which was generated by the AppForge Database Converter, to the VB project. This can be via the Project|Add Module in the Visual Basic menu. The module contains all the necessary code for directly accessing the Palm database, leaving you responsible for adding the appropriate code in the Visual Basic events.
When the AppForge Button Ingots are clicked, an event is raised as with any VB control. Using these events, it's easy to add records, navigate the existing records, or delete records. Additionally, depending on the button, you assign database information to the appropriate AppForge Ingot that is on the form. Listing One is all you need for this project.
Perhaps the best feature that AppForge provides is the ability to test the application from within the VB IDE without the need of an emulator or device. You can simply run it like any VB application and test the program functions. If you would prefer to download the application to a device or the Palm OS emulator (http://www.palm.com/), you first need to compile it and then copy both the Booster run time and the Palm executable.
With the popularity of the Palm exceeding that of Windows CE and other PDA OSs, it's important to have a variety of development tools to choose from. AppForge for Visual Basic offers everything you need.
DDJ
Private NewRecord As Boolean
Private Sub btnBack_Click()
PDBMovePrev dbSigsTime
DisplayInfo
End Sub
Private Sub btnExit_Click()
Unload Me
End Sub
Private Sub btnNext_Click()
PDBMoveNext dbSigsTime
DisplayInfo
End Sub
Private Sub btnDelete_Click()
If NewRecord Then
ClearDisplay
NewRecord = False
DisplayInfo
ElseIf PDBNumRecords(dbSigsTime) > 0 Then
PDBDeleteRecord dbSigsTime
DisplayInfo
Else
MsgBox "No records to delete"
End If
End Sub
Private Sub btnNew_Click()
NewRecord = True
lblRecordDisplay.Caption = "New"
txtDate.Text = ""
txtTime.Text = ""
ClearDisplay
End Sub
Private Sub btnSave_Click()
Dim MyRecord As tSigsTimeRecord
If NewRecord Then
PDBCreateRecordBySchema dbSigsTime
End If
MyRecord.Name = txtName.Text
MyRecord.Signature = sigName.SignatureData
MyRecord.Date = txtDate.Text
MyRecord.Time = txtTime.Text
PDBEditRecord dbSigsTime
WriteSigsTimeRecord MyRecord
PDBUpdateRecord dbSigsTime
DisplayInfo
End Sub
Private Sub Form_Load()
If OpenSigsTimeDatabase = False Then
#If APPFORGE Then
dbSigsTime = PDBCreateDatabase("SigsTime",
SigsTime_TypeID, SigsTime_CreatorID)
#Else
dbSigsTime = PDBCreateDatabase(App.Path & "\SigsTime",
SigsTime_TypeID, SigsTime_CreatorID)
#End If
PDBCreateTable dbSigsTime, "Signatures",
"Name String, Signature String"
End If
PDBMoveFirst dbSigsTime
DisplayInfo
End Sub
Private Sub DisplayInfo()
Dim MyRecord As tSigsTimeRecord
If PDBNumRecords(dbSigsTime) > 0 Then
NewRecord = False
ReadSigsTimeRecord MyRecord
txtName.Text = MyRecord.Name
sigName.SignatureData = MyRecord.Signature
txtDate.Text = MyRecord.Date
txtTime.Text = MyRecord.Time
lblRecordDisplay.Caption = CStr(PDBCurrentIndex(dbSigsTime) + 1) +
" of " + CStr(PDBNumRecords(dbSigsTime))
Else
NewRecord = True
lblRecordDisplay.Caption = "0 of 0"
ClearDisplay
End If
End Sub
Private Sub ClearDisplay()
sigName.Clear
txtName.Text = ""
End Sub