Page 1
Page 2

Next add a Module to the PocketPC project
and name it modMain. It really isn't important which
project you add the Module to, but again, it'll make this
tutorial simpler if we're on the same page.
Next let's implement some abstration.
Double-click on the CommandButton to get the default event
handler cmdHi_Click on the code page. Instead of
putting our implementation code here, we're going to simply
provide a single line that calls another method in modMain.
My convention for naming the called
function is to use the form name as a prefix to the method.
In this case it ends up frmMain_cmdHi_Click(). You'll
notice that the FormOK_Click event will already be
there, and we can go ahead and leave it for this tutorial.
So the following is what we end up with:
Option Explicit
Private Sub cmdHi_Click()
frmMain_cmdHi_Click
End Sub
Private Sub Form_OKClick()
App.End
End Sub
Now, in modMain, we add our actual implementation
code:
Option Explicit
Public Sub frmMain_cmdHi_Click()
MsgBox "Hello " & frmMain.txtName.Text
End Sub
At this point, compile, debug if necessary
and run your project to make sure everything is working
as desired. Once you're satisfied, make sure you've saved
your project, then open up the HPC Pro project. Select Project
| Add File from the menu and add the modMain from the PocketPC
project to this project. Now we just need to add the single
method call to cmdHi's Click event handler.
Option Explicit
Private Sub cmdHi_Click()
frmMain_cmdHi_Click
End Sub
You'll notice that the code in the actual
Form files is remarkably similar. This is what we want.
In fact all of the code in a project can just be cut-and-pasted
from one project to the other. Sure, you might end up with
a Form_OKClick() handler in a project that has no Form OK,
but that won't cause any errors if you forget to remove
it. It's just code that never gets executed, and if you
keep up with the abstraction, it's only three lines of code.
In this tutorial the benefits of this
abstraction aren't very big, but in a large project the
benefits are substantial. With this technique I've been
able to port an HPC Pro project that took two month to develop
to the PocketPC platform in less than two days, including
menu functionality. You also get the added benefit that
any fixes or changes that you implement in one application
inherently effects the other application.
Remember, anything to decrease support
resources decreases application costs and helps keep developers
sane. Abstraction is a good to keep your projects on the
right track.
Previous Page