hb++ - absolutebeginnerguide

53
© 2005 - 2006 ... Skinny Frog Software HB++ Absolute Beginner's Guide Experience makes us all geniuses. HB++ is a trademark of Peter Holmes Consulting. Palm OS, Palm Computing, Graffiti, HotSync, PalmSource are registered trademarks of PalmSource, Inc. or its affiliates. Palm, the Palm logo, the HotSync logo, Palm Powered, the Palm trade dress, are trademarks of PalmSource, Inc. or its affiliates. Metrowerks and CodeWarrior are registered trademarks of Metrowerks Corp in the US and other countries. Microsoft, Microsoft Paint, Visual Basic, Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and / or other countries. Java is a registered trademark of Sun Microsystems, Inc. in the US and other countries. Motorola is registered in the US Patent & Trademark Office. ARM is a registered trademark of ARM Limited. All other products and brand names may be trademarks or registered trademarks of their respective owners. Color Wheel Expert is copyrighted software by Abitom Software, all rights reserved. If I neglected to mention any others, their rights are reserved too. An internet connection is required for web links. Contact us at [email protected]

Upload: suportedistribuidora

Post on 08-Sep-2014

161 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: HB++ - AbsoluteBeginnerGuide

© 2005 - 2006 ... Skinny Frog Software

HB++ Absolute Beginner's GuideExperience makes us all geniuses.

HB++ is a trademark of Peter Holmes Consulting. Palm OS, Palm Computing, Graffiti, HotSync, PalmSource are registered trademarks of PalmSource, Inc.or its affiliates. Palm, the Palm logo, the HotSync logo, Palm Powered, the Palm trade dress, are trademarks of PalmSource, Inc. or its affiliates. Metrowerksand CodeWarrior are registered trademarks of Metrowerks Corp in the US and other countries. Microsoft, Microsoft Paint, Visual Basic, Windows are eitherregistered trademarks or trademarks of Microsoft Corporation in the United States and / or other countries. Java is a registered trademark of SunMicrosystems, Inc. in the US and other countries. Motorola is registered in the US Patent & Trademark Office. ARM is a registered trademark of ARMLimited. All other products and brand names may be trademarks or registered trademarks of their respective owners. Color Wheel Expert is copyrightedsoftware by Abitom Software, all rights reserved. If I neglected to mention any others, their rights are reserved too.

An internet connection is required for web links.

Contact us at [email protected]

Page 2: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's GuideI

© 2005 - 2006 ... Skinny Frog Software

Table of Contents

Foreword 1

Introduction 2

................................................................................................................................... 21 Why use Handheld Basic?

................................................................................................................................... 32 Becoming a Palm PDA programmer

Work Diary Example 5

................................................................................................................................... 51 Overview

................................................................................................................................... 72 Getting Started

.......................................................................................................................................................... 10Adding to the Project

.......................................................................................................................................................... 11tblWD

.......................................................................................................................................................... 12Main Form

......................................................................................................................................................... 13Building the Form

......................................................................................................................................... 14Adding Controls

................................................................................................................................... 15Adding Grid1

................................................................................................................................... 16Adding Grid2

................................................................................................................................... 17Adding Labels

................................................................................................................................... 17Adding Grafitti Indicator

................................................................................................................................... 17Adding Text Fields

................................................................................................................................... 18Adding Category Box

................................................................................................................................... 18Adding Buttons & Menus

......................................................................................................................................... 19Adding Subroutines

......................................................................................................................................... 19Adding Functions

......................................................................................................................................... 19Adding Graphics

......................................................................................................................................................... 20The Complete Code - frmMain

.......................................................................................................................................................... 22View Form

......................................................................................................................................................... 23Building the Form

......................................................................................................................................... 26Adding Controls

................................................................................................................................... 27Adding Text Fields

................................................................................................................................... 28Adding Grafitti Indicator

................................................................................................................................... 28Adding Category Box

................................................................................................................................... 28Adding Buttons & Menus

................................................................................................................................... 30Adding a Message Box

................................................................................................................................... 30Adding Labels

......................................................................................................................................... 30Adding Subroutines

......................................................................................................................................... 31Adding Functions

......................................................................................................................................... 32Adding Graphics

......................................................................................................................................................... 33The Complete Code - frmView

.......................................................................................................................................................... 38Memo Form

......................................................................................................................................................... 38Building the Form

......................................................................................................................................... 39Adding Controls

................................................................................................................................... 40Adding Text Fields

................................................................................................................................... 41Adding Grafitti Indicator

................................................................................................................................... 41Adding Buttons & Menus

......................................................................................................................................... 41Adding Functions

......................................................................................................................................... 42Adding Graphics

......................................................................................................................................................... 42The Complete Code - frmMemo

.......................................................................................................................................................... 43About Form

Page 3: HB++ - AbsoluteBeginnerGuide

IIContents

II

© 2005 - 2006 ... Skinny Frog Software

......................................................................................................................................................... 43Building the Form

......................................................................................................................................... 44Adding Controls

................................................................................................................................... 44Adding Labels

................................................................................................................................... 45Adding Images

......................................................................................................................................................... 45The Complete Code - frmAbout

................................................................................................................................... 453 Wrapup

.......................................................................................................................................................... 45Classes and Modules

......................................................................................................................................................... 46The Complete Class Code - clsApplication

......................................................................................................................................................... 46The Complete Class Code - clsFormMenu

......................................................................................................................................................... 47The Complete Module Code - modDB

Index 49

Page 4: HB++ - AbsoluteBeginnerGuide

Foreword

This help document is provided free of charge by thedevelopers at Skinny Frog Software.

It is meant as a guide to those just starting out in theamazing world of Palm programming. We at SkinnyFrog Software hope it helps.

Foreword1

© 2005 - 2006 ... Skinny Frog Software

Page 5: HB++ - AbsoluteBeginnerGuide

Introduction 2

© 2005 - 2006 ... Skinny Frog Software

1 Introduction

"Experience makes us all geniuses."

If you are like me, writing programs is not what I do for a living. I have alwaysadmired programmers though, for what they can make a computer do. Perhapsthat's the reason for my interest in it. I do not see myself as ever being aprofessional programmer (selling Palm apps excluded). Still, it is brain food, andwhether or not I'm good at it, I can't get enough.

If you are like me, you have a small fortune invested in programming literature.Some books are well suited for the novice, and I appreciate those authors thatwrite for their audience rather than for their peers. I can get so frustrated at timesas I'm reading along then all of a sudden come across a statement or somethingthat tosses a wrench into my gearbox. What in the world does that mean? It meanswhen I've read something that I don't understand I magically transform into the trial-and-error king. I think I know what it should mean, but am not certain. I justhave to see. If I'm correct, then I'll give myself a "that-a-boy" ('cause I'm not asdumb as I look) but if not, then I mumble ('cause I'm am as dumb as I look) "razzle-dazzle-friggin-@!#%$. Where's a sample?!"

The aim of this booklet is towards the HB++ beginner interested in programmingPDA devices. In no way, form, or fashion is it aimed at those that are "gifted." So, ifyou are one of those, or a proven programmer, this is not for you.

The objective of this booklet is to take a simple program, one of my own called Work Diary, break it down into little-bitty pieces, and try to understand what it allmeans. With that in mind, I'll attempt to show you how to create forms with datafields, menus, control buttons, graphics, and images, and more.

If at any time, and I mean any time, you feel that you'll never get it, just remember: "Experience makes us all geniuses."

1.1 Why use Handheld Basic?

I see comments in green, red numbers too, I see lots of code for me and you, then I thinkto myself, what a wonderful world

With HB++ there are no limits.

Forum ...The HB++ forum is, without exception, the very best in the world.

There are no stupid questions! If you've got an HB++ or Palm question, then ask it.Most of the time you will get a reply from the HB++ Team within a matter of

Page 6: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide3

© 2005 - 2006 ... Skinny Frog Software

minutes. Hey! I'm not kidding! Don't despare if it doesn't happen as I've said,because the Team is probably trying to recreate your problem, and you'd beastonished that while you wait another member has probably already responded.

It's simply the best forum I have ever come across.

You absolutely must become a member!

Samples and Examples ...The best way to learn is by example, and HB++ comes with many diverse samplesand examples to help you learn.

Help Documentation ...The HB++ Help document has over 1000 pages covering every aspect of thatcompiler.

Let's take a quick look at a few common terms:Class Member Object Show

Instance Special Identifiers Operators Design Time

Functions Event Properties Forms

Controls Statements Segment Data Types

Looking up terms is easy.

1.2 Becoming a Palm PDA programmer

I'll be there in just a minute honey!

First and foremost, have you asked your family if it would be alright for you to dothis?

Because once you are bitten, it is addictive, very addictive. Minutes turn into hours,which turn into days, which ... well, you get the picture. For you, time has nomeaning, but in the real world it does, so learn to partition your time. I'm notkidding!

Well now, with that said, you will need a few resources... .

Tools ...You will need some tools to get started. If you haven't already, you will need todownload the latest version of HB++. At the time of this writing that version is 1.05.It is a fully functional, time limit free, development environment and compiler. It's isfreely available from Peter Holmes Consulting.

If you haven't already done so, you really should become a registered developerat Palm Source. Their development registration opens the door for all sorts ofgoodies. The registration is free, and is well worth your time. Oh, and while you arethere become familiar with the Creator ID section. Each of your applications should

Page 7: HB++ - AbsoluteBeginnerGuide

Introduction 4

© 2005 - 2006 ... Skinny Frog Software

be registered with Palm as a unique creator ID.

After registering, you will need a few items. Depending on the version of operatingsystem you plan to build your programs too, you will need to download the emulator and/or the simulator, or both. They're free. You will also have to read theiragreement and agree to it to download their various ROMs. They're free too.

Oh, you don't have a PDA yet, but were just interested in developing programs.Ok, you will need to download and install the latest version of the Palm Desktop.It's free. The desktop provides a HotSync Manager, which opens the pipelinebetween your computer and your device, and emulator/simulator. That's right, youdon't need a device as long as you have the desktop and emulator/simulator.

To see how to setup the HotSync with the emulator and simulator go here.

Documents ...Palm documents provide the best overall description. All documents are availablefor download from Palm Source. Special attention should be given to the PalmUser Interface document. This describes the "do's" and "don'ts" of designing yourapplication. Don't forget that a PDA is not a computer like your PC or laptop, andyou cannot design your program as if it were. There are restrictions!

The HB++ documentation is superb. It is packed with descriptions and definitions,language references, and example code snippets. There are over 1000 pages tothis document, so it is hefty, and a lot of thought has gone into it. It is alsodistributed with all versions of HB++. I suggest strongly you read through it.

Web Sites ...Several HB++ developers have graciously provided help pages on their web sites.

· Jon's web site hosts tutorials for the HB++ Autograph and Delivery samples (included with the HB++ download), and when you are ready, a nice tutorial onConduits as well.

· Linda's web site which offers you an abundance of resources and links.

And of course, there is my web site, which provides interactive tutorials, all free fordownloading. I apologize for my not spending more time creating additionaltutorials (it's because of my day job). I promise to add more in the near future.

I also invite you to visit other HB++ developers web sites where possible. Thesefolks really have some good applications, not to mention they can give you someideas about programming. Go see what's out there, then go create that programthat isn't out there.

Once you have tested your program and are ready to distribute it, several host /e-commerce facilities are available for your applications. Of course, there is your

Page 8: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide5

© 2005 - 2006 ... Skinny Frog Software

own web site, but a couple of major ones are PalmGear and Handango. However,these services aren't free. At the time of this writing, both hosts charge a fee of40% of your application price. You can expect to get your royalty payment(s) oncea quarter.

2 Work Diary Example

The Work Diary is a simple database program that logs the date, time, charge perhour, calculates earnings,and stores contact information of any job. It can be usedto track overtime at work, parttime jobs, outside tasks, just about any type of workcan be tracked. It is actually quite simple and easy to use. In other words, it is userfriendly. Too many Bells and Whistles's make my head hurt.

I chose to use it as an example because it is simple, and because it covers manyof the basic fundamentals of HB++ programming such as text fields, controlbuttons, grids, and binds the information to a table.

You can let this example become your building block for other applications, so feelfree to experiment and have fun!

2.1 Overview

The first two forms below are the main forms of the application.

The first form (Work Diary form - frmMain) provides a list view of Job Location,Date, Charge, Hours, and Earnings (the latter three are not shown in this image).By tapping on the the grid view field (Science Mart or John's Porch), the secondform (Information form - frmView) appears.

The Find field let's you enter any letter, a partial or complete word, and if it existsin the data table, it will show up in the grid view box as only those records meetingthat condition. It's a good way to filter through a grid view box having many rows ofdata. There is a drop-down box titled Jobs. Jobs serves as a quick search bycategory, such as Overtime, Parttime, Gigs, Other. Records that have not beensaved to a particular category or that do not fit into a category are stored in Unfiled. There is a utility associated with the drop-down box, Edit Categories.... and itprovides a way to edit current or add more categories.

There are two ways to call up the Information form from the Work Diary form. Thefirst method is to tap on any occupied row in the grid view box. You are essentiallysaying, "let me edit or delete this record." The second method is by tapping theNew Job control button. Here you are saying, "let me add a new record to mytable." If New Job is tapped, the Information form appears with all fields blank. Ifyou change your mind, tapping Cancel on the Information form takes you back tothe Work Diary form.

Page 9: HB++ - AbsoluteBeginnerGuide

Work Diary Example 6

© 2005 - 2006 ... Skinny Frog Software

The second form (Information form) is where the important work data is stored.The drop-down box defaults to Unfiled for the categories, but you may select acategory for your information to fall under. The other field are typical contact datafields. I wanted to spruce the form's look up a bit so I added rectangle graphicswith color. Notice on the Earnings field that by placing two rectangle graphics withdifferent colors gives off an illusion of depth. Other rectangle graphics are aroundthe Charge and Hour fields, and around the control buttons New, Delete, Cancel,and Done. Notice I didn't use frames around the buttons, and the underlines forTotal Hours and Earnings are set not to show.

Because of limited window space on the PDA, a menu was added to the Title Bar.As you can see from the menu I can navigate to other forms as well as performediting events.

These two forms are noncrucial, but are necessary. The Memo form (frmMemo) isasscociated with the Information form to provide an additional field for trackingimportant events of the day. It is a multiple line text field. A scrollbar automaticallyappears if your entry exceeds the four lines shown. On any text field that iseditable, a grafitti indicator should be added. The About form (frmAbout) simplyshows what the application is about.

Page 10: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide7

© 2005 - 2006 ... Skinny Frog Software

2.2 Getting Started

Just the basic facts, M'am!

See this first ...

Determining the number of forms needed ...Before construction and development begin for a project, you should have an ideaof what you want accomplish. For Work Diary, the concept is simple: one form isneeded to support basic information such as name, address, phone number,etcetera. Another form is needed to provide a quick look without having to navigatethrough one record after another. Another form is needed for additional notes.Because the plan is to distribute the application, a form is needed to showspecifics about the application. In all, four forms are needed.

I think it is important to choose a single form from the group and let it be the pivotform for which all others are bound and called.

Give the forms names... The name of the forms in Work Diary are: Main, View, Memo, and About. Althoughthe Main form will be set to show at startup, the View form will be my pivot form.

Determining what needs to be included in each form ...Below is a listing of what I thought should be on each form.

Main formTitlebar: Work DiaryFields: FindLabels: FindMenu: Exit <Quit>, About <About Work Diary> Objects: Categories <Jobs [All, Gigs, Other, Overtime, Partime, Unfiled, Edit Categories...] >, Grid1, Grid 2, Scrollbar 1, Scrollbar 2Buttons: New JobTable: tblWD

View formTitlebar: InformationFields: Date, Contact, Location, Address, Phone, Earnings, Charge, Hours From, Hours To,Minutes From, Minutes To, Total Hours

Page 11: HB++ - AbsoluteBeginnerGuide

Work Diary Example 8

© 2005 - 2006 ... Skinny Frog Software

Labels: Date, Contact, Location, Address, Phone, Earnings, Charge, Time From, hr, min, TimeTo, hr, min,Total HoursMenu: Menu <Cut, Copy, Paste, Select All,Keyboard, Grafitti Help>, View Memo <Memo>, About<About Work Diary> Objects: Categories, Grafitti IndicatorButtons: New, Delete, Cancel, DoneTable: tblWD

Memo formTitlebar: MemoFields: TextButtons: OkObjects: Grafitti IndicatorTable: tblWD

About formTitlebar: AboutLabels: Application Title, Version, Promotional, Developer, Web AddressObjects: Bitmap

Determining the application's appearance ...Colors can be assigned to any part of the form. I assigned red to the cursor, andindigo to the text. Default for both is black. The HB++ Help document has a listingof HB++ predefined color constants, and a HTML color table. You are notrestricted to these colors though. I like to use a tool called Color Wheel Expert toaid me with colors and their values.

I'm using one image (bitmap) in my application, but I will use it in a couple of ways.First, in the About form, and secondly as my application icon. Each bitmap imagemust be included in an image family before it can be used. For my images I useWindows Paint. In order to highlight certain areas on the forms, I use rectangleand line graphics.

from the IDE Project window

Then register as the application icon.

from the IDE Project menu > Settings

Page 12: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide9

© 2005 - 2006 ... Skinny Frog Software

Assigning the Creator ID ...Before any development is done, it is a good idea to go ahead and generate a Ceator ID for your application. As you can see, I've assigned WrK2 as thisapplication's Creator ID. And, of course I registered it with Palm. It is always agood idea to do that because suppose your application has the same Creator IDas another. That's a problem, and it's doubtful your application will run properly.

from the IDE Project menu > Settings

The IDE's Project menu shows all properties for the project.

Page 13: HB++ - AbsoluteBeginnerGuide

Work Diary Example 10

© 2005 - 2006 ... Skinny Frog Software

2.2.1 Adding to the Project

Adding to your project is easy and can be done in just a couple of clicks with themouse.

To add a new form, a new class, a new module, a new image, or a new tablesimply highlight the project property, use the right-click on the mouse then make aselection. Follow the instructions in new window.

Afterwards, don't forget to rename your new addition. For example, after adding anew form I renamed it frmAbout.

Alternatively, the same can be done by using the IDE's Project menu. Follow theinstructions in the new window.

Page 14: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide11

© 2005 - 2006 ... Skinny Frog Software

To add a menu to the project, click on the IDE's Menu icon. A drop box will appear.You will need to add a New Menu first. Give it a name, then add a New Item. TheNew Item button allows you to add items to the menu. Here, I added About WorkDiary.

2.2.2 tblWD

I added a table to the application and called it tblWD. Without a table, I cannotsave my data. Record numbers 1 through 4 are required fields for every HB++table and are included by default. These should NOT be modified. The remainingrecords are specific to Work Diary, and are used to bind the form's fields with this

Page 15: HB++ - AbsoluteBeginnerGuide

Work Diary Example 12

© 2005 - 2006 ... Skinny Frog Software

table.

In the HB++ table, the Data Type can be changed by simply tapping the data typefield and making a selection.

2.2.3 Main Form

The code examples for frmMain are snippet-based and will not run as is.

Note: The different colored rectangle graphics are defined in the Form_Paint()subroutine.

At the end of this session is the complete code for this form.

Page 16: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide13

© 2005 - 2006 ... Skinny Frog Software

2.2.3.1 Building the Form

Titlebar: Work DiaryFields: FindLabels: FindMenu: Exit (Quit), About (About Work Diary) Objects: Categories <Jobs (All, Gigs, Other, Overtime, Partime, Unfiled, Edit Categories)>, Grid1,Grid2, Scrollbar1, Scrollbar2, Grafitti IndicatorButtons: New Job

frmMain Properties:

.

Page 17: HB++ - AbsoluteBeginnerGuide

Work Diary Example 14

© 2005 - 2006 ... Skinny Frog Software

...

2.2.3.1.1 Adding Controls

The highlighted controls are used in constructing this form.

Page 18: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide15

© 2005 - 2006 ... Skinny Frog Software

Controls Help

2.2.3.1.1.1 Adding Grid1

Grid1 is used as the main view box. More information about the grid.

The Grid1 must be loaded before it can be viewed. Instructions are needed to tellthe compiler in what order we want the data, and where to find the data. Here, weask it to go to the table, tblWD, which has been given the alias name, db, andretrieve the information stored in the mentioned fields.

Each column in our grid is recognized by an integer index value. The compilerrecognizes 0 as the first column index, so it must be used as the first column index,followed by the second column index, 1, and so on. The term vValue is aparameter of the grid, and is saying, "add this data item to the grid in this column."

Private Sub Grid1_LoadItem(ByVal iRow As Integer, ByVal lItemData As Long, ByVal vValue() AsVariant)

vValue(0)=db.CompanyvValue(1)=db.DatevValue(2)=db.ChargevValue(3)=db.TDiffvValue(4)=db.Earnings

Page 19: HB++ - AbsoluteBeginnerGuide

Work Diary Example 16

© 2005 - 2006 ... Skinny Frog Software

End Sub

The Grid is there for a reason, right? We want it to do more than simply show thedata. In fact, we want it to react to some action by the user. Essentially, we wantthe user to be able to click on any row in the grid view box and be taken to thatdata set in the Information form. The Click() event is where this action instruction isplaced.

Telling the compiler which grid row has been selected, and which data set toretrieve, is first done by declaring an arbritrary variable k as an integer. By writingDim k As Integer, then setting the variable k as a grid row with a value greater thanor equal to the first item index, we are telling the compiler "if the row exists, look upit's UniqueID from the data table (db) and bring it up."

In order to call the data set to the Information form, it must be set to show up afterthe Click() event. We first declare a new instance of the Information form bywriting Dim f As New frmView, then calling it from the instruction, f.ShowhbFormGoto+hbFormModeless. The Information form shows up with the data setselected from the grid view box. Note: f. associates frmView with Show

Private Sub Grid1_Click(ByVal iRow As Integer, ByVal iCol As Integer, ByVal lItemData As Long)Dim k as IntegerDim f as New frmView

k=grid1.rowIf k>=0 Then

db.LookupUniqueID grid1.ItemData(k)f.Show hbFormGoto+hbFormModeless

End IfEnd Sub

The scrollbar is a utility control allowing us to view more records than currently inthe grid view box. Here we are simply setting it's property to the value of theposition of the first column. Note: In the Property window for GridEx1 we set thevertscroll property to Scrollbar1 and not to Scrollbar2. We want to control its actionthrough code.

Private Sub Scrollbar2_Scroll(ByVal iValue As Integer)grid1.LeftCol=iValue

End Sub

2.2.3.1.1.2 Adding Grid2

Grid2 is used as the header for the main view box. More information about the grid.

Because it is being used as a header for the main view box, we want it to show upon the form regardless of data being present for the grid view box. Here, we assigna single row to the grid (our header).

Private Sub Form_Load()grid2.AddItem 0

End Sub

Page 20: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide17

© 2005 - 2006 ... Skinny Frog Software

Each column in our grid is recognized by an integer index value rather than by astring (or name.) The compiler recognizes 0 as the first column index, so it must beused as the first column index, followed by the second column index, 1, and so on.The term vValue is a parameter of the grid, and is saying, "add this data item to thegrid in this column." Unlike Grid1 where we asked the compiler to look for datawithin the data table, all we want from Grid2 are header strings (or names) whichwe have identified.

Private Sub Grid2_LoadItem(ByVal iRow As Integer, ByVal lItemData As Long, ByVal vValue() AsVariant)

vValue(0)="Job Location"vValue(1)="Date"vValue(2)="Charge"vValue(3)="Hours"vValue(4)="Earnings"

End Sub

The scrollbar is a utility control allowing us to view more records than currently inthe grid view box. Here we are simply setting it's property to the value of theposition of the first column. Note: In the Property window for GridEx2 we do not setthe vertscroll property like we did for GridEx1. We want GridEx2 and Scrollbar2 tobe associated with GridEx1, and control its actions through code.

Private Sub Scrollbar2_Scroll(ByVal iValue As Integer)grid2.LeftCol=iValue

End Sub

2.2.3.1.1.3 Adding Labels

Labels can be placed arbitrarily on the form. Placement is determined solely on thedesign.

2.2.3.1.1.4 Adding Grafitti Indicator

The Grafitti Indicator should be used on any form where the text field is editable.

2.2.3.1.1.5 Adding Text Fields

This form uses only one text field, Find. It's properties are set through the form'sProperty window. Text fields are usually aligned with labels and this one's label isalso called Find. It's good practice to name the text field as close to its meaning aspossible.

When the frmMain is loaded, we want the cursor to focus on the the Find text field.

Private Sub Form_Load()Set Focus=fldFind

End Sub

The purpose of the Find text field is to allow the user to enter either a letter, apartial or complete word, then have the application perform a search andcompare, or a match, to their input from the existing records. After this action is

Page 21: HB++ - AbsoluteBeginnerGuide

Work Diary Example 18

© 2005 - 2006 ... Skinny Frog Software

complete, we want the main view box to show only those records that meet ourcriteria. A call to the Change() event makes this happen. Filllist is a subroutinedesigned for that purpose.

Private Sub fldFind_Change()FillList

End Sub

2.2.3.1.1.6 Adding Category Box

Let the compiler know that this variable, iCategory, is an integer.

Private iCategory as Integer

Load the category box with the caption "Jobs".

Private Sub Form_Load()popCategory.Text="Jobs"

End Sub

The items in the catagory box are actually list items. Assigning the arbitraryvariable k as an integer tells the compiler to look for the item index value of thecategory list, and if an item exists, show it. More information on the format ofCategorySelect.

Private Sub popCategory_Click()Dim k as Integer

k=popCategory.CategorySelect(db,iCategory,1,True,True)If k<>iCategory Then 'if it is not empty

iCategory=kEnd If

End Sub

2.2.3.1.1.7 Adding Buttons & Menus

We first declare a new instance of the Information form by writing Dim f As NewfrmView, then calling it from the instruction, f.Show hbFormGoto+hbFormModeless.With the Click() event the Information form shows up.

The boolean f.bNew, used in frmView, performs a special action when theInformation form shows.

Note: f. associates frmView with bNew and Show.

Private Sub cmdNew_Click()Dim f as New frmView

f.bNew=Truef.Show hbFormGoto+hbFormModeless

End Sub

With the Click() event, the menu item Exit (Quit) closes the application by a simplecall to the app method quit.

Page 22: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide19

© 2005 - 2006 ... Skinny Frog Software

Private Sub mnuQuit_Click()app.Quit

End Sub

2.2.3.1.2 Adding Subroutines

Set the inital value of the index to nothing.

Private Sub Initialize()iCategory=-1

End Sub

This procedure does a lot of work! It is saying, "if a record exists, or if modificationsare made to a record, or a search is made on a letter, partial or whole word, then fillthe main view box with this information." The Redraw property determines whetherthe grid is updated immediately after a change. You can use this property to improvethe performance of your program and prevent the grid from flickering when you addor modify several items in it.

Private Sub FillList()Dim s as String, n as Integers=Trim(fldFind.Text)n=Len(s)Grid1.Redraw=FalseGrid1.Rows=0

If db.RecordCount>0 Thendb.MoveFirstWhile Not db.EOF

If iCategory=-1 Or db.Category=iCategory ThenIf StrComp(Left(db.Company,n),s,hbCompareText)=0 Then

Grid1.AddItem db.UniqueIDEnd If

End Ifdb.MoveNextWendEnd If

flush 'clear the graphics buffer. Grid1.Redraw=True

End Sub

2.2.3.1.3 Adding Functions

This form does not use functions.

2.2.3.1.4 Adding Graphics

The UIColor() event let's us change objects from their default colors. The changesmust be identified when the form loads. Here we are changing the default colors tothree objects. I think color values in hexadecimal are easy to work with.

Private Sub Form_Load()UIColor(hbUIFieldCaret) = &H00FF0000

Page 23: HB++ - AbsoluteBeginnerGuide

Work Diary Example 20

© 2005 - 2006 ... Skinny Frog Software

UIColor(hbUIFieldText) = &h00336666UIColor(hbUIObjectForeground) = &H00000066

End Sub

Adding flavor to the form via lines and rectangles must be identified in the Form_Paint() event. If graphics are not identified in that event, then they will notshow up on the form at run-time. The ForeColor assigns a color value to thegraphic. The coordinate positions for the line and rectangle are similar: start x, starty, end x, end y. The rectangle offers a few more options, such as border style andfill type.

private sub form_paint()ForeColor = &H00C0C0C0rectangle 1,29,158,139,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00000066rectangle 0,28,159,140,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00000066rectangle 1,143,158,155,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00000066line 89,143,89,156

ForeColor = &H00C0C0C0line 90,143,90,156

ForeColor = &H00000066line 91,143,91,156

ForeColor = &H00C0C0C0rectangle 0,142,159,156,hbRectBorderSolid+hbRectFillNone

End Sub

Recall from the Palm User Interface Guidelines that the normal screen dimensionsare 160 by 160 (width by height).

2.2.3.2 The Complete Code - frmMain

Public lLastUniqueID as LongPrivate iCategory as Integer

Private Sub Initialize()lLastUniqueID=-1iCategory=-1

End Sub

Private Sub Form_Load()grid2.AddItem 0

UIColor(hbUIFieldCaret) = &H00FF0000UIColor(hbUIFieldText) = &h00336666UIColor(hbUIObjectForeground) = &H00000066

popCategory.Text="Jobs"Filllist

Page 24: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide21

© 2005 - 2006 ... Skinny Frog Software

Set Focus=fldFindEnd Sub

private sub form_paint()ForeColor = &H00C0C0C0rectangle 1,29,158,139,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00000066rectangle 0,28,159,140,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00000066rectangle 1,143,158,155,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00000066line 89,143,89,156

ForeColor = &H00C0C0C0line 90,143,90,156

ForeColor = &H00000066line 91,143,91,156

ForeColor = &H00C0C0C0rectangle 0,142,159,156,hbRectBorderSolid+hbRectFillNone

End Sub

Private Sub popCategory_Click()Dim k as Integerk=popCategory.CategorySelect(db,iCategory,1,True,True)

If k<>iCategory TheniCategory=kFillList

End IfEnd Sub

Private Sub fldFind_Change()FillList

End Sub

Private Sub FillList()Dim s as String, n as Integers=Trim(fldFind.Text)n=Len(s)Grid1.Redraw=FalseGrid1.Rows=0

If db.RecordCount>0 Thendb.MoveFirstWhile Not db.EOF

If iCategory=-1 Or db.Category=iCategory ThenIf StrComp(Left(db.Company,n),s,hbCompareText)=0 Then

Grid1.AddItem db.UniqueIDEnd If

End Ifdb.MoveNextWendEnd If

flushGrid1.Redraw=True

Page 25: HB++ - AbsoluteBeginnerGuide

Work Diary Example 22

© 2005 - 2006 ... Skinny Frog Software

End Sub

Private Sub cmdNew_Click()Dim f as New frmView

f.bNew=Truef.Show hbFormGoto+hbFormModeless

End Sub

Private Sub mnuQuit_Click()app.Quit

End Sub

Private Sub Grid2_LoadItem(ByVal iRow As Integer, ByVal lItemData As Long, ByVal vValue() AsVariant)

vValue(0)="Job Location"vValue(1)="Date"vValue(2)="Charge"vValue(3)="Hours"vValue(4)="Earnings"

End Sub

Private Sub Grid1_LoadItem(ByVal iRow As Integer, ByVal lItemData As Long, ByVal vValue() AsVariant)db.LookupUniqueID lItemData

vValue(0)=db.CompanyvValue(1)=db.DatevValue(2)=db.ChargevValue(3)=db.TDiffvValue(4)=db.Earnings

End Sub

Private Sub Grid1_Click(ByVal iRow As Integer, ByVal iCol As Integer, ByVal lItemData As Long)Dim k as IntegerDim f as New frmViewk=grid1.rowIf k>=0 Then

db.LookupUniqueID grid1.ItemData(k)f.Show hbFormGoto+hbFormModeless

End IfEnd Sub

Private Sub Scrollbar2_Scroll(ByVal iValue As Integer)grid1.LeftCol=iValuegrid2.LeftCol=iValue

End Sub

2.2.4 View Form

The code examples for frmView are snippet-based and will not run as is.

Page 26: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide23

© 2005 - 2006 ... Skinny Frog Software

Note: The red cursor and the indigo text are defined in the Form_Load()subroutine.

The different colored rectangle and line graphics are defined in the Form_Paint() subroutine.

At the end of this session is the complete code for this form.

2.2.4.1 Building the Form

Titlebar: InformationFields: Date, Contact, Location, Address, Phone, Earnings, Charge, Hours From, Hours To, MinutesFrom, Minutes To, Total HoursLabels: Date, Contact, Location, Address, Phone, Earnings, Charge, Time From, hr, min, Time To,hr, min,Total HoursMenu: Menu (Cut, Copy, Paste, Select All,Keyboard, Grafitti Help), View Memo (Memo), About (About Work Diary) Objects: Categories <Jobs (All, Gigs, Other, Overtime, Partime, Unfiled, Edit Categories)>, GrafittiIndicatorButtons: New, Delete, Cancel, Done

frmView Properties:

Page 27: HB++ - AbsoluteBeginnerGuide

Work Diary Example 24

© 2005 - 2006 ... Skinny Frog Software

Page 28: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide25

© 2005 - 2006 ... Skinny Frog Software

Page 29: HB++ - AbsoluteBeginnerGuide

Work Diary Example 26

© 2005 - 2006 ... Skinny Frog Software

.

2.2.4.1.1 Adding Controls

The highlighted controls are used in constructing this form.

Page 30: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide27

© 2005 - 2006 ... Skinny Frog Software

Controls Help

2.2.4.1.1.1 Adding Text Fields

Let the compiler know that frmMemo is called m.

public m as new frmMemo

When the form loads, fill the text fields with data from these records. The Newcontrol button sets these text fields as blanks.

Private Sub Form_Load()Set Focus=fldDate

fldDate.Text=db.DatefldEarnings.Text=db.EarningsfldContact.Text=db.ContactfldCompany.Text=db.CompanyfldAddress.Text=db.Address1fldPhone.Text=db.PhonefldCharge.Text=db.ChargefldHFrom.Text=db.HFromfldMFrom.Text=db.MFromfldHTo.Text=db.HTofldMTo.Text=db.MTofldTDiff.Text=db.TDiffm.Field1.Text=db.Memo 'load the data from the Memo form

End Sub

Page 31: HB++ - AbsoluteBeginnerGuide

Work Diary Example 28

© 2005 - 2006 ... Skinny Frog Software

2.2.4.1.1.2 Adding Grafitti Indicator

The Grafitti Indicator should be used on any form where the text field is editable.

2.2.4.1.1.3 Adding Category Box

Let the compiler know that this variable, iCategory, is an integer.

Private iCategory as Integer

When the form loads, look to see if it is a new category selection. If it is, then callthe selection from the record. But if it isn't, then set the category to it's defaultvalue. In the form, show the caption of the selection.

Private Sub Form_Load()If bNew Then

iCategory=0ElseiCategory=db.CategoryEnd IfpopCategory.Text=db.CategoryName(iCategory)

End Sub

The items in the catagory box are actually list items. Assigning the arbitraryvariable k as an integer tells the compiler to look for the item index value of thecategory list, and if and item exists, show it. If we have made a different selectionfrom the list of items, then tell the compiler the list choice has been modified. Notethere is a slight difference in the format of CategorySelect here as opposed to theCategorySelect on the Main form. More information on the format of CategorySelect.

Private Sub popCategory_Click()Dim k as Integerk=popCategory.CategorySelect(db,iCategory,1,False,True)

If k<>iCategory TheniCategory=kbModified=True

End IfEnd Sub

2.2.4.1.1.4 Adding Buttons & Menus

When the form loads, hide the Delete control button if it is a new instance of theform, otherwise, show the button.

Private Sub Form_Load()If bNew Then

cmdDelete.Visible=False 'override this control Property window settingsElse

cmdDelete.Visible=TrueEnd If

End Sub

Before this record is deleted, ask the user if this is really what they want to do. Ifthe answer is "yes" then go ahead and delete the record, otherwise cancel the

Page 32: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide29

© 2005 - 2006 ... Skinny Frog Software

action.

Private Sub cmdDelete_Click()Dim r as HbMsgBoxReturnDim f as new frmMain

r=MsgBox("Delete this record ?",hbMsgBoxYesNo+hbMsgBoxConfirmation)If r=hbMsgBoxYes Then

db.Delete hbRecordDelete 'delete this recordf.Show hbFormGoto+hbFormModeless

End IfEnd Sub

If there are no errors, such as leaving blank text fields, then we're done and cansave this record and leave this form. If there are blank text fields, then ask theuser politely to fill in the blanks. Do all calculations on time before leaving.

Private Sub cmdDone_Click()on error goto ErrDim f as new frmMainDim lID as long

call timecalc() 'time calculationslID=SaveChangesf.lLastUniqueID=lIDf.Show hbFormGoto+hbFormModeless

exit subErr:if fldCharge.Text = "" or fldHFrom.Text = "" or fldMFrom.Text = "" or fldHTo.Text = "" orfldMTo.Text = "" then

msgbox "These fields cannot be left blank. Please enter a numeric value, or 0 if you aren'tcollecting charges or time.",hbMsgBoxError,"Charge/Time Input Field Error!"set focus = fldCharge

elsef.Show hbFormGoto+hbFormModeless

exit sub 'go back and fill in the blanksend if

End Sub

Give me a blank form ready for adding data to a new record.

Private Sub cmdNew_Click()bModified=TruebNew=TrueSaveChanges

fldDate.Text=""fldEarnings.Text=""fldContact.Text=""fldCompany.Text=""fldAddress.Text=""fldPhone.Text=""fldCharge.Text=""fldHFrom.Text=""fldMFrom.Text=""fldHTo.Text=""fldMTo.Text=""fldTDiff.Text=""m.Field1.Text=""

Page 33: HB++ - AbsoluteBeginnerGuide

Work Diary Example 30

© 2005 - 2006 ... Skinny Frog Software

Set Focus=fldDatecmdDelete.Visible=FalseiCategory=0

End Sub

Cancel this action and take me back to the Main form.

Private Sub cmdCancel_Click() Dim fMain as frmMain

Set fMain = New frmMain 'do not want to create a "new" instance of the Main formfMain.Show hbFormModeless+hbFormGoto

End Sub

From the menu, take me to the Memo form

Private Sub mnuMemo_Click()dim m as new frmMemo

m.Show hbFormPopup+hbFormGotoEnd Sub

2.2.4.1.1.5 Adding a Message Box

The message box allows us to speak to the user, and then perform some action.Here the action displays a message then takes us to the Main form.

Dim r as HbMsgBoxReturnDim f as new frmMain

r=MsgBox("<say something here>",hbMsgBoxYesNo+hbMsgBoxConfirmation)If r=hbMsgBoxYes Then

<do something here>f.Show hbFormGoto+hbFormModeless

End If

2.2.4.1.1.6 Adding Labels

Labels can be placed arbitrarily on the form. Placement is determined solely on thedesign.

2.2.4.1.2 Adding Subroutines

This may not be the best approach, but it works.

'...........Time Calculations................private sub timecalc()dim earnings as Doubledim time1 as Double, time1h as Double, time1m as Doubledim time2 as Double, time2h as Double, time2m as Doubledim timediff as Double, tdiff as Doubledim charge as Double

'time fromtime1h = cdbl(me.fldHFrom.text)time1m = cdbl(me.fldMFrom.Text)/60

Page 34: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide31

© 2005 - 2006 ... Skinny Frog Software

time1 = time1h + time1m

'time totime2h = cdbl(me.fldHTo.Text)time2m = cdbl(me.fldMTo.Text)/60time2 = time2h + time2m

'12 hour timeif (time2h = time1h) and (time2m > time1m) then

timediff = time2 - time1 charge = cdbl(me.fldCharge.Text)earnings = abs(timediff)*chargetdiff = earnings/charge

elseif (time2h = time1h) then timediff = time2 - time1 + 12charge = cdbl(me.fldCharge.Text)earnings = abs(timediff)*chargetdiff = earnings/charge

elseif (time2h < time1h) thentimediff = time2 - time1 + 12charge = cdbl(me.fldCharge.Text)earnings = abs(timediff)*chargetdiff = earnings/charge

elsetimediff = time1-time2charge = cdbl(me.fldCharge.Text)earnings = abs(timediff)*chargetdiff = earnings/charge

end if

'earningsme.fldEarnings.Text = format((earnings),"0.00")

'total hours workedme.fldTDiff.Text = tdiff

End Sub

2.2.4.1.3 Adding Functions

A few declarations are made to let the compiler know whether or not the data hasbeen modified, or if it is new data. Also, that frmMemo will be known as m, and thatthe category value is an integer value.

Public bNew as BooleanPrivate bModified as BooleanPrivate iCategory as Integerpublic m as new frmMemo

This function tells the compiler to save our data. It is says that if the data has beenmodified (bModified is true), then check if it is new data and if it is, add it to the

Page 35: HB++ - AbsoluteBeginnerGuide

Work Diary Example 32

© 2005 - 2006 ... Skinny Frog Software

data set; if it is not, then we must have edited the data in these fields, including thefield on the Memo form. Either way, we want to update the data set in the table.The UniqueID is a long integer value uniquely ("only one of its kind") assigned tothat record. All records have a unique ID. Here we ask the compiler to save thedata by its UniqueID no matter whether it was edited or new data.

Private function SaveChanges() as longIf bModified Then

If bNew Then ''Add a recorddb.AddNew

Elsedb.Edit

End Ifdb.Date=fldDate.Textdb.Earnings=fldEarnings.Textdb.Contact=trim(fldContact.Text)db.Company=trim(fldCompany.Text)db.Address1=fldAddress.Textdb.Phone=fldPhone.Textdb.Charge=fldCharge.Textdb.HFrom=fldHFrom.Textdb.MFrom=fldMFrom.Textdb.HTo=fldHTo.Textdb.MTo=fldMTo.Textdb.TDiff=fldTDiff.Textdb.Memo=m.Field1.Text 'add record from memo formdb.Category=iCategorydb.Update

SaveChanges=db.UniqueIDElse

If bNew ThenSaveChanges=db.UniqueID

ElseSaveChanges=db.UniqueID

End IfEnd IfbNew=False

End Function

2.2.4.1.4 Adding Graphics

The UIColor() event let's us change objects from their default colors. The changesmust be identified when the form loads. Here we are changing the default colors totwo objects. I think color values in hexadecimal are easy to work with.

Private Sub Form_Load()UIColor(hbUIFieldCaret) = &H00FF0000UIColor(hbUIFieldText) = &H001E1464

End Sub

Adding a little flavor to the form via lines and rectangles must be identified in the Form_Paint() event. If graphics are not identified in that event, then the they willnot show up on the form at run-time. The ForeColor assigns a color value to thegraphic. The coordinate positions for the line and rectangle are similar: start x, start

Page 36: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide33

© 2005 - 2006 ... Skinny Frog Software

y, end x, end y. The rectangle offers a few more options, such as border style andfill type.

private sub form_paint()ForeColor = &H00000066rectangle 85,18,158,31,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00C0C0C0rectangle 84,17,159,31,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00000066rectangle 0,99,159,140,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00CDFFCCrectangle 1,100,158,140,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00000066rectangle 2,101,157,139,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00C0C0C0rectangle 1,143,158,155,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00000066rectangle 0,142,159,156,hbRectBorderSolid+hbRectFillNone

End Sub

Recall from the Palm User Interface Guidelines that the normal screen dimensionsare 160 by 160 (width by height).

2.2.4.2 The Complete Code - frmView

Public bNew as BooleanPrivate bModified as BooleanPrivate iCategory as Integerpublic m as new frmMemo

Private Sub Form_Load()UIColor(hbUIFieldCaret) = &H00FF0000UIColor(hbUIFieldText) = &H001E1464

Set Focus=fldDatebModified=False

If bNew ThenSet Focus=fldDatecmdDelete.Visible=FalseiCategory=0

ElsefldDate.Text=db.DatefldEarnings.Text=db.EarningsfldContact.Text=db.ContactfldCompany.Text=db.CompanyfldAddress.Text=db.Address1fldPhone.Text=db.PhonefldCharge.Text=db.ChargefldHFrom.Text=db.HFromfldMFrom.Text=db.MFrom

Page 37: HB++ - AbsoluteBeginnerGuide

Work Diary Example 34

© 2005 - 2006 ... Skinny Frog Software

fldHTo.Text=db.HTofldMTo.Text=db.MTofldTDiff.Text=db.TDiffm.Field1.Text=db.Memo

cmdDelete.Visible=TrueiCategory=db.CategoryEnd IfpopCategory.Text=db.CategoryName(iCategory)

End Sub

private sub form_paint()ForeColor = &H00000066rectangle 85,18,158,31,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00C0C0C0rectangle 84,17,159,31,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00000066rectangle 0,99,159,140,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00CDFFCCrectangle 1,100,158,140,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00000066rectangle 2,101,157,139,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00C0C0C0rectangle 1,143,158,155,hbRectBorderSolid+hbRectFillNone

ForeColor = &H00000066rectangle 0,142,159,156,hbRectBorderSolid+hbRectFillNone

End Sub

Private Sub popCategory_Click()Dim k as Integerk=popCategory.CategorySelect(db,iCategory,1,False,True)

If k<>iCategory TheniCategory=kbModified=True

End IfEnd Sub

Private Sub cmdDelete_Click()Dim r as HbMsgBoxReturnDim f as new frmMain

r=MsgBox("Delete this record ?",hbMsgBoxYesNo+hbMsgBoxConfirmation)If r=hbMsgBoxYes Then

db.Delete hbRecordDeletef.Show hbFormGoto+hbFormModeless

End IfEnd Sub

Private Sub cmdDone_Click()on error goto Err

Dim f as new frmMainDim lID as long

call timecalc()

Page 38: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide35

© 2005 - 2006 ... Skinny Frog Software

lID=SaveChangesf.lLastUniqueID=lIDf.Show hbFormGoto+hbFormModeless

exit sub

Err:if fldCharge.Text = "" or fldHFrom.Text = "" or fldMFrom.Text = "" or fldHTo.Text = "" orfldMTo.Text = "" then

msgbox "These fields cannot be left blank. Please enter a numeric value, or 0 if you aren'tcollecting charges or time.",hbMsgBoxError,"Charge/Time Input Field Error!"set focus = fldCharge

elsef.Show hbFormGoto+hbFormModeless

exit subend if

End Sub

Private function SaveChanges() as longIf bModified Then

If bNew Then 'Add a recorddb.AddNew

Elsedb.Edit

End Ifdb.Date=fldDate.Textdb.Earnings=fldEarnings.Textdb.Contact=trim(fldContact.Text)db.Company=trim(fldCompany.Text)db.Address1=fldAddress.Textdb.Phone=fldPhone.Textdb.Charge=fldCharge.Textdb.HFrom=fldHFrom.Textdb.MFrom=fldMFrom.Textdb.HTo=fldHTo.Textdb.MTo=fldMTo.Textdb.TDiff=fldTDiff.Textdb.Memo=m.Field1.Textdb.Category=iCategorydb.Update

SaveChanges=db.UniqueIDElse

If bNew ThenSaveChanges=db.UniqueID

ElseSaveChanges=db.UniqueID

End IfEnd IfbNew=False

End Function

Private Sub cmdNew_Click()bModified=TruebNew=TrueSaveChanges

fldDate.Text=""fldEarnings.Text=""fldContact.Text=""

Page 39: HB++ - AbsoluteBeginnerGuide

Work Diary Example 36

© 2005 - 2006 ... Skinny Frog Software

fldCompany.Text=""fldAddress.Text=""fldPhone.Text=""fldCharge.Text=""fldHFrom.Text=""fldMFrom.Text=""fldHTo.Text=""fldMTo.Text=""fldTDiff.Text=""m.Field1.Text=""

Set Focus=fldDatecmdDelete.Visible=FalseiCategory=0

End Sub

Private Sub fldDate_Change()bModified=True

End SubPrivate Sub fldContact_Change()

bModified=TrueEnd SubPrivate Sub fldCompany_Change()

bModified=TrueEnd SubPrivate Sub fldPhone_Change()

bModified=TrueEnd SubPrivate Sub fldAddress_Change()

bModified=TrueEnd SubPrivate Sub fldCharge_Change()

bModified=TrueEnd SubPrivate Sub fldEarnings_Change()

bModified=TrueEnd SubPrivate Sub fldHFrom_Change()

bModified=TrueEnd SubPrivate Sub fldHTo_Change()

bModified=TrueEnd SubPrivate Sub fldMFrom_Change()

bModified=TrueEnd SubPrivate Sub fldMTo_Change()

bModified=TrueEnd SubPrivate sub fldTDiff_Change()

bModified=TrueEnd Sub

Private Sub cmdCancel_Click() Dim fMain as frmMain

Set fMain = New frmMainfMain.Show hbFormModeless+hbFormGoto

End Sub

Page 40: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide37

© 2005 - 2006 ... Skinny Frog Software

Private Sub mnuMemo_Click()dim m as new frmMemo

m.Show hbFormPopup+hbFormGotoEnd Sub

'...........Time Calculations................private sub timecalc()dim earnings as Doubledim time1 as Double, time1h as Double, time1m as Doubledim time2 as Double, time2h as Double, time2m as Doubledim timediff as Double, tdiff as Doubledim charge as Double

'fromtime1h = cdbl(me.fldHFrom.text)time1m = cdbl(me.fldMFrom.Text)/60time1 = time1h + time1m

'totime2h = cdbl(me.fldHTo.Text)time2m = cdbl(me.fldMTo.Text)/60time2 = time2h + time2m

'12 hourif (time2h = time1h) and (time2m > time1m) then

timediff = time2 - time1 charge = cdbl(me.fldCharge.Text)earnings = abs(timediff)*chargetdiff = earnings/charge

elseif (time2h = time1h) then timediff = time2 - time1 + 12charge = cdbl(me.fldCharge.Text)earnings = abs(timediff)*chargetdiff = earnings/charge

elseif (time2h < time1h) thentimediff = time2 - time1 + 12charge = cdbl(me.fldCharge.Text)earnings = abs(timediff)*chargetdiff = earnings/charge

elsetimediff = time1-time2charge = cdbl(me.fldCharge.Text)earnings = abs(timediff)*chargetdiff = earnings/charge

end if

'chargeme.fldEarnings.Text = format((earnings),"0.00")

'hours workedme.fldTDiff.Text = tdiff

End Sub

Page 41: HB++ - AbsoluteBeginnerGuide

Work Diary Example 38

© 2005 - 2006 ... Skinny Frog Software

2.2.5 Memo Form

The code examples for frmMemo are snippet-based and will not run as is.

Note: The red cursor and the indigo text are defined in the Form_Load()subroutine.

At the end of this session is the complete code for this form.

2.2.5.1 Building the Form

Titlebar: MemoFields: TextButtons: OkObjects: Grafitti Indicator

frmMemo Properties:

Page 42: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide39

© 2005 - 2006 ... Skinny Frog Software

.

2.2.5.1.1 Adding Controls

The highlighted controls are used in constructing this form.

Page 43: HB++ - AbsoluteBeginnerGuide

Work Diary Example 40

© 2005 - 2006 ... Skinny Frog Software

Controls Help

2.2.5.1.1.1 Adding Text Fields

This form uses only one text field, field1. It's properties are set through the form'sProperty window. Text fields are usually aligned with labels and this one's label isalso called field1. It's good practice to name the text field as close to its meaningas possible.

When the frmMemo is loaded, we want the cursor to focus on the the field1 textfield. I got lazy and did not give this text field a "proper" name. If it is a new memowe want the text field to be blank, and if it is not, then show it with the associatedrecord.

Private Sub Form_Load()If bNew Then

Set Focus=field1Else

Field1.Text=db.MemoEnd If

End Sub

Page 44: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide41

© 2005 - 2006 ... Skinny Frog Software

2.2.5.1.1.2 Adding Grafitti Indicator

The Grafitti Indicator should be used on any form where the text field is editable.

2.2.5.1.1.3 Adding Buttons & Menus

We're finished so save the changes and take me back to the View form, and letthe Main form know that changes have been made to this record.

Private Sub cmdDone_Click()Dim f as new frmViewdim fm as new frmMainDim lID as long

lID=SaveChangesfm.lLastUniqueID=lIDf.Show hbFormGoto+hbFormModeless

End Sub

2.2.5.1.2 Adding Functions

A couple of declarations are made to let the compiler know whether or not the datahas been modified, or if it is new data.

Public bNew as BooleanPrivate bModified as Boolean

This function tells the compiler to save our data. It is says that if the data has beenmodified (bModified is true), then check if it is new data and if it is, add it to thedata set; if it is not, then we must have edited the data in this field. Either way, wewant to update the data set in the table. The UniqueID is a long integer valueuniquely ("only one of its kind") assigned to that record. All records have a uniqueID. Here we ask the compiler to save the data by its UniqueID no matter whether itwas edited or new data.

Private function SaveChanges() as longIf bModified Then

If bNew Then 'Add a recorddb.AddNew

Elsedb.Edit

End Ifdb.Memo=Field1.Textdb.UpdateSaveChanges=db.UniqueID

ElseIf bNew Then

SaveChanges=db.UniqueIDElse

SaveChanges=db.UniqueIDEnd If

End IfbNew=False

End Function

Page 45: HB++ - AbsoluteBeginnerGuide

Work Diary Example 42

© 2005 - 2006 ... Skinny Frog Software

2.2.5.1.3 Adding Graphics

The UIColor() event let's us change objects from their default colors. The changesmust be identified when the form loads. Here we are changing the default colors totwo objects. I think color values in hexadecimal are easy to work with.

Private Sub Form_Load()UIColor(hbUIFieldCaret) = &H00FF0000UIColor(hbUIFieldText) = &H001E1464

End Sub

2.2.5.2 The Complete Code - frmMemo

Public bNew as BooleanPrivate bModified as BooleanPrivate Sub Form_Load()

UIColor(hbUIFieldCaret) = &H00FF0000UIColor(hbUIFieldText) = &H001E1464

Set Focus=field1bModified=FalseIf bNew Then

Set Focus=field1Else

Field1.Text=db.MemoEnd If

End Sub

Private Sub cmdDone_Click()Dim f as new frmViewdim fm as new frmMainDim lID as long

lID=SaveChangesfm.lLastUniqueID=lIDf.Show hbFormGoto+hbFormModeless

End Sub

Private function SaveChanges() as longIf bModified Then

If bNew Then 'Add a recorddb.AddNew

Elsedb.Edit

End Ifdb.Memo=Field1.Textdb.UpdateSaveChanges=db.UniqueID

ElseIf bNew Then

SaveChanges=db.UniqueIDElse

SaveChanges=db.UniqueIDEnd If

End IfbNew=False

End Function

Page 46: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide43

© 2005 - 2006 ... Skinny Frog Software

Private Sub Field1_Change()bModified=True

End Sub

2.2.6 About Form

The code examples for frmAbout are snippet-based and will not run as is.

Note: Notice there isn't a control button?

At the end of this session is the complete code for this form.

2.2.6.1 Building the Form

Titlebar: AboutLabels: Application Title, Version, Promotional, Developer, Web AddressObjects: Bitmap

frmAbout Properties:

Page 47: HB++ - AbsoluteBeginnerGuide

Work Diary Example 44

© 2005 - 2006 ... Skinny Frog Software

.

2.2.6.1.1 Adding Controls

The highlighted controls are used in constructing this form.

Controls Help

2.2.6.1.1.1 Adding Labels

Labels can be placed arbitrarily on the form. Placement is determined solely on thedesign.

Page 48: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide45

© 2005 - 2006 ... Skinny Frog Software

2.2.6.1.1.2 Adding Images

The About form is for displaying information about the application. No data ispassed from here.

We don't add code for the image here since it can be done through the form's Property window.

Setting the label caption and concatenating (&, ampersand symbol) it with the appmethod Version is easy. Whatever the version identified in the Project settingswindow will appear here.

Private Sub Form_Load()lblVersion.Caption="Version " & App.Version

End Sub

Notice there aren't any calls for control buttons? That's because there aren't any. Iwanted to allow the user to tap anywhere on the form and it close. For this use the PenUp() event.

The simpliest method to close a modal form is to use the Unload Me.

Private Sub Form_PenUp(ByVal x As Integer, ByVal y As Integer)Unload Me

End Sub

2.2.6.2 The Complete Code - frmAbout

Private Sub Form_Load()lblVersion.Caption="Version " & App.Version

End Sub

Private Sub Form_PenUp(ByVal x As Integer, ByVal y As Integer)Unload Me

End Sub

2.3 Wrapup

We're almost finished.

2.3.1 Classes and Modules

The clsApplication class is the default class generated with every new applicationcreated with the HB++ new project wizard. A new blank project will not generatethe clsApplication, and thereby will not generate a call to theApplication_NormalLaunch() event. It must contain at the very least a call to thisevent. Without it, the application will not run. Additional procedures can be addedas needed, such as telling the compiler which form to startup with.

Page 49: HB++ - AbsoluteBeginnerGuide

Work Diary Example 46

© 2005 - 2006 ... Skinny Frog Software

Additional classes and modules may be added as needed. For Work Diary, weadded an additional class, clsFormMenu, to handle calls to the menu procedures.We adding modDB to handle our data table, recordsets, and to initialize bits ofdata for the application startup.

2.3.1.1 The Complete Class Code - clsApplication

Private Sub Application_NormalLaunch()dim f as new frmMain

InitScreenModeSet db=OpenDatabase(hbModeReadWrite)f.Show hbFormModeless+hbFormGoto

End Sub

Public Sub InitScreenMode()Dim sc as New ScreenModeDim b as Boolean

b=sc.FindFirstModeWhile b

If sc.BitDepth<=8 ThenSet ScreenMode=scExit Sub

End Ifb=sc.FindNextModeWend

End Sub

2.3.1.2 The Complete Class Code - clsFormMenu

Public mnuCut as MenuItemPublic mnuCopy as MenuItemPublic mnuPaste as MenuItemPublic mnuSelect as MenuItemPublic mnuKeyboard as MenuItemPublic mnuGraffiti as MenuItemPublic mnuAbout as MenuItem

Public Sub mnuCut_Click()Dim f as Field

'Get the focus FieldSet f=Focus'if a field have the focus, then invoke the Cut method else beepIf f Is Nothing Then SystemSound Else f.Cut

End Sub

Public Sub mnuCopy_Click()Dim f as Field

'Get the focus FieldSet f=Focus'if a field have the focus, then invoke the Copy method else beepIf f Is Nothing Then SystemSound Else f.Copy

End Sub

Public Sub mnuPaste_Click()Dim f as Field

'Get the focus FieldSet f=Focus

Page 50: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide47

© 2005 - 2006 ... Skinny Frog Software

'if a field have the focus, then invoke the Paste method else beepIf f Is Nothing Then SystemSound Else f.Paste

End Sub

Public Sub mnuSelect_Click()Dim f as Field

'Get the focus FieldSet f=Focus'if a field have the focus, then select all else beepIf f Is Nothing Then

SystemSoundElse

f.SelStart=0f.SelLength=32767

End IfEnd Sub

Public Sub mnuKeyboard_Click()Dim f as Field

'Get the focus FieldSet f=Focus'if a field have the focus, then call the virtual keyboard else beepIf f Is Nothing Then SystemSound Else SystemDialog hbSysKeyboardDefault

End Sub

Public Sub mnuGraffiti_Click()Dim f as Field

'Get the focus FieldSet f=Focus'if a field have the focus, then call the graffiti help dialog box else beepIf f Is Nothing Then SystemSound Else SystemDialog hbSysGraffitiReference

End Sub

Public Sub mnuAbout_Click()Dim f as New frmAbout'Show the About formf.Show hbFormModal+hbFormPopup

End Sub

2.3.1.3 The Complete Module Code - modDB

Public db as tblWDPublic Function OpenDatabase(ByVal eAccessMode as HbMode) as tblWDDim db as New tblWDDim e as Integer

On Error Goto NotFoundStart:

db.OpenTable hbModeOpenExisting+eAccessModeSet OpenDatabase=dbdb.MoveLast

Exit Function

NotFound:e=Err.NumberIf e<>43 Then Err.Raise edb.OpenTable hbModeCreateAlways+hbModeReadWrite

Page 51: HB++ - AbsoluteBeginnerGuide

Work Diary Example 48

© 2005 - 2006 ... Skinny Frog Software

'categoriesdb.CategoryName(0)="Unfiled"db.CategoryName(1)="Overtime"db.CategoryName(2)="Gigs"db.CategoryName(3)="Parttime"db.CategoryName(4)="Other"

'initilize some datadb.AddNewdb.Company="Science Mart"db.Contact="Pat Evans"db.Address1="5234 E. Westinghouse Drive"db.Phone="548-9833"db.Date="21 July 04"db.Charge="45.00"db.HFrom="8"db.MFrom="30"db.HTo="12"db.MTo="00"db.TDiff="3.50"db.Earnings="17.50"db.Category=0db.Update

db.AddNewdb.Company="John's porch"db.Contact="John Brown"db.Address1="Rt. #2, Old Mill Rd"db.Phone="878-5454"db.Date="3 Sep 2004"db.Charge="20.00"db.HFrom="6"db.MFrom="30"db.HTo="4"db.MTo="30"db.TDiff="10.00"db.Earnings="200.00"db.Category=0db.Update

db.Close

Goto StartEnd Function

Page 52: HB++ - AbsoluteBeginnerGuide

HB++ Absolute Beginner's Guide49

© 2005 - 2006 ... Skinny Frog Software

Index- A -Adding Buttons & Menus 18

Adding Category Box 18

Adding Controls (frmAbout) 44

Adding Controls (frmMain) 14

Adding Controls (frmMemo) 39

Adding Controls (frmView) 26

Adding Functions 19

Adding Functions (frmView) 31

Adding Grid #1 15

Adding Grid2 16

Adding Images 45

Adding Labels 17

Adding Subroutines 19

Adding Text Fields 17

Adding to the Project 10

alias 15

application icon 7

arbritrary variable 15

Assigning the Creator ID 7

- C -CategorySelect 18

Class 2

Classes and Modules 45

clsApplication 46

clsFormMenu 46

Controls 2

Controls Help 14

Creator ID 3

- D -Data Type 11

Data Types 2

declarations 41

Design Time 2

- E -editable 17

emulator 3

Event 2

Experience makes us all geniuses 2

- F -Form (frmMain) 13

Form_Paint 19

Forms 2

frmAbout Properties 43

frmMain Properties 13

frmMemo Properties 38

frmView Properties 23

Functions 2

- G -Getting Started 7

Grafitti Indicator 17

- H -Handango 3

HB++ forum 2

header 16

Help Documentation 2

hexadecimal 19

HotSync 3

- I -IDE's Menu icon 10

IDE's Project menu 10

Instance 2

integer index value 15

interactive tutorials 3

- L -Labels 17

Page 53: HB++ - AbsoluteBeginnerGuide

Index 50

© 2005 - 2006 ... Skinny Frog Software

- M -Main Form 12

Member 2

modal form 38

modDB 47

More information about the grid 15

- O -Object 2

Operators 2

Overview 5

- P -Palm Desktop 3

Palm documents 3

Palm Source 3

Palm User Interface Guidelines 19

PalmGear 3

Peter Holmes Consulting 3

Properties 2

- R -resources and links 3

- S -Samples and Examples 2

See this first 7

Segment 2

Show 2

simulator 3

Special Identifiers 2

Statements 2

string 16

- T -table 11

tblWD 15

The Complete Code - frmAbout 45

The Complete Code - frmMain 20

The Complete Code - frmMemo 42

The Complete Code - frmView 33

the IDE Project window 7

Time Calculations 30

Tools 3

tutorials 3

- U -UIColor 19

UniqueID 31

utility control 16

- V -vValue 15

- W -Work Diary download 5