Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Sapphire Soltuions

Making eMbedded Visual Basic Applications Portable Using Abstraction

Written by Christopher Tacke  [author's bio]  [read 41239 times]
Edited by Derek

Download the code

Page 1  Page 2 

Portability. It's something VB programmers haven't worried about, or probably even thought about since the times of the 486, Windows 3.x and VB 4. Sure, when VB 5 was released there were still some hold out customers that wanted 16 bit applications, but for the most part the notion of VB code needing to address portability went the way of the dinosaur when Windows 95 and 98 had fully taken over the PC market.

That was until CE came along. Of course eMbedded Visual Basic is still interpreted code, so as VB developers we still don't have to worry about compiling for specific processors like C++ developers do, but there are still multiple platforms. We often have to address the fact that a client may want to run an application on both a PocketPC and an HPC Pro.

The first, most obvious hurdle that you must overcome is the simple real-estate issue. A Pocket PC's screen is 260x320, whereas the HPC Pro might be either 480x24 0 or 480x480.

Then there are the more subtle differences: the PocketPC uses a MenuBar control instead of a menu, the PocketPC has a Form OK button, ADOCE connections and recordsets have to be created from different libraries (i.e. ADOCE.Connection.3.0 on the PocketPC versus just ADOCE.Connection on the HPC Pro), The SIP, form closing events. The list goes on.

If there's anything I hate doing as a developer, it's repeating myself. Duplicating code across projects not only is tedious, it's dangerous. It makes maintenance a nightmare. Bug fixes, as well as upgrades and feature changes have to be made in multiple places, and the more lines of code you have, the greater the probability of making a mistake or error.

The first key to making solutions portable in the CE world is abstraction - moving the code out of the form and into BAS files that you can call from anywhere. This includes all event handling from the forms.

Let's begin by developing the ubiquitous "Hello World" application to run on the PocketPC and the HPC Pro. We'll have a textbox to enter our name and a button that, when clicked, displays out "Hello" message.

First create two project files, one for each platform, and, if eVB didn't do it for you, add one Form to each project. Next add a CommandButton and TextBox to each Form. The properties for each are not terribly important, except for one - keep the names of analogous controls across projects identical. To make things easier, name both forms frmMain, both CommandButtons cmdHi and both TextBoxes txtName and save the projects in separate folders. You can see what I ended up with in Figures 1 and 2.

Next Page