Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Palm Development with MobileVB : Page 4

Now, in version 3.5, MobileVB is a well thought-out add-in for VB6 that alleviates the drawn-out development process and makes Palm OS programming a viable option for even novice VB programmers.


advertisement
Writing Some Code
The module you added to the project contains all the necessary code for directly accessing the Palm Database, leaving you responsible for adding the appropriate code in the VB events. When the button Ingots are clicked, an event is raised. Using these events, it's easy to add records, navigate the existing records, or delete records. Begin with the creation of a new record, which occurs when btnNew is clicked.

Along with the Palm OS, MobileVB provides templates for the Pocket PC, Symbian P800, and the Nokia Communicator.
Begin by opening the Code window to create a variable called NewRecord. The variable should be of type Boolean; that is, it holds a yes/no, true/false, or 1/0 value. Inside the btnNew_Click event, begin by setting the NewRecord variable to True. Next, set txtItem and txtQuantity to "". You'll be setting the TextBoxes to "" on several occasions and with that in mind, create a new procedure called ClearDisplay to set them. Then call the procedures as needed. The following procedures are finished:

Private NewRecord As Boolean Private Sub btnNew_Click() NewRecord = True ClearDisplay End Sub Private Sub ClearDisplay() txtQuantity.Text = "" txtItem.Text = "" End Sub

Next, handle the forward and back (<- and ->) buttons. The code is nearly identical for both items and looks like this:

Private Sub btnBack_Click() PDBMovePrev dbInv DisplayInfo End Sub Private Sub btnNext_Click() PDBMoveNext dbInv DisplayInfo End Sub

The next item is the btnDelete code. Again, it uses the ClearDisplay sub procedure and the NewRecord variable. It checks to see if there is a record, and if so, deletes it. Here is the code:



Private Sub btnDelete_Click() If NewRecord Then ClearDisplay NewRecord = False DisplayInfo ElseIf PDBNumRecords(dbInv) > 0 Then PDBDeleteRecord dbInv DisplayInfo Else MsgBox "No records to delete" End If End Sub

Before moving on, let's look at the Form_Load event. This event checks to see if the database exists and if not, creates a new one. You'll also move to the first record in the database. The code you need is in Listing 1.

At the end, the Form_Load event calls the DisplayInfo sub procedure. This procedure (in Listing 1) contains the code that actually displays the information on the screen. You only have two buttons left to deal with. The first is btnSave, which saves the database record you currently have displayed, and btnExit, which causes the program to end. The following procedures finish the application:

Private Sub btnSave_Click() Dim MyRecord As tInvRecord If NewRecord Then PDBCreateRecordBySchema dbInv End If MyRecord.Item = txtItem.Text MyRecord.Quantity = txtQuantity.Text PDBEditRecord dbInv WriteInvRecord MyRecord PDBUpdateRecord dbInv DisplayInfo End Sub Private Sub btnExit_Click() Unload Me End Sub

MobileVB does a splendid job of integrating Palm development into the VB IDE, and is undoubtedly one of the easiest to use all-around development tools available for the Palm. The tools are especially easy to use for developers that are already experienced with VB, as the learning curve is nearly nonexistent. If you are a VB developer and want to write software for mobile devices like the Palm OS, look no further.



Clayton Crooks is an award winning author and consultant based in Knoxville, TN. Clayton's most recent book, Developing Tablet PC Applications, was published by Charles River Media. You will find additional information at his Web site, www.claytoncrooks.com. Reach him at crooks@starband.net.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date