Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

.NET

AppForge: Visual Basic for the Palm OS


Aug01: AppForge: Visual Basic for the Palm OS

Clayton is an independent developer and can be contacted at [email protected].


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:

  • A compiler and utilities for packaging and transferring compiled applications to devices.
  • Special ActiveX controls called "Ingots" that replace the standard VB intrinsic controls when a Palm application is being developed.

  • The Booster run-time engine, which is freely available to anyone who wants to run an AppForge application on their device. The AppForge Booster replaces the standard VB run-time DLL and consists of native code that runs AppForge applications on a Palm OS-based mobile device.

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.

Creating an Application

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.

The GUI

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.

Database

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.

Creating the Code

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.

Testing the Application

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.

Conclusion

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

Listing One

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

Back to Article


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.