Page 1 of 1

dialog dbcombo looping

Posted: Sun Sep 02, 2012 1:44 pm
by brewster
I am using a dialog box with 2 dbcombos as a trip calculator.
The user chooses an origin and drop point and that is where I want some text or perhaps a MsgAlert() to display a calculated
km value - within the dialog to calc as many times as needed without having to start the dialog again.

I' ve tried variations of ON CHANGE oKm:seek or a say clause on the calc button, but I have to activate the dialog to do the calc and the MsgAlert() will appear with the km. I'm obviously coding it wrong.

oTcomp holds the company longnames and cod(code) fields which then are seeked in oKm
oTkm has a combination of 2 cod(company codes) with a fixed km value for that trip.

Help

Bruce S

FW 6/12
Harbour v3.1 Rev 17222
ilinl32 6.21



//--------
.dbfs set here

DEFINE DIALOG oDlg FROM -50, 15 TO -35, 75 ;
TITLE " Trip Distance Calculator"


@ .5, 6 SAY "&Origin" OF oDlg SIZE 22, 11
@ 21, 8 dbcombo oDBC1 var cOrg of oDlg;
alias oTcomp:cAlias;
size 100,250 pixel;
itemfield "COD" ;
listfield "COMP";
update;



@ .5, 26 SAY "&Drop" OF oDlg SIZE 22, 11
@ 21, 128 dbcombo oDBC1 var cDrp of oDlg;
alias oTcomp:cAlias;
size 100,250 pixel;
itemfield "COD" ;
listfield "COMP";
update;


@ 3,12 say 'Minimum trip fee - $ ' + trans(nMin,'99.99');
FONT fntArial SIZE 125,25 OF oDlg




@ 5, 11 BUTTON "&Calc" OF oDlg SIZE 40, 12 ACTION oDlg:End() //Say( 6, 2, cOrg + ' / '+ cDrp + ' ' )
@ 5, 21 BUTTON "&Exit" OF oDlg SIZE 40, 12 ACTION oDlg:End()


ACTIVATE DIALOG oDlg CENTERED



If oTkm:seek(cOrg+cDrp) = .t.

nKm := KM

nCost := iif(nKm * ( nL_rate + nFactor) < nMin, nMin,nKm * ( nL_rate + nFactor) )


MsgInfo( space(2)+ trans(nKm,'999.99') + " km = " +;
" $ " + trans(nCost,'9999.99')+ space(3)," Trip cost")

else

If empty(cOrg) .or. empty(cDrp)

MsgInfo(" Incomplete trip data ")

Else

MsgInfo(" That trip data was not found ")

Endif

Endif


fntArial:End()


return nil

Re: dialog dbcombo looping

Posted: Sun Jan 06, 2013 1:11 am
by James Bott
Bruce,

If you haven't already solved this, here are some suggestions.

I would use the CHANGE clause of Dbcombo to do the calculation and then display it on the dialog using a SAY control.

I would also removed the "Calculate" button and change the "Exit" button to "Close." Close is standard Windows convention for a dialog that is not updating a database. "Exit" is standard for exiting an application. If this dialog is the entire application then "Exit" would be the proper term.

I don't see why you would need any traps for missing or invalid data since you are using a combobox. The only data that can be in the vars is valid data from the databases.

Regards,
James

Re: dialog dbcombo looping

Posted: Fri Jan 25, 2013 1:18 pm
by brewster
James,
Appreciate your comments on my threads circa Jan 5/13.
Any input helps this work in progress.

I use the "traps for invalid data" because an empty selection always seems to come along with a combobox, which I don't want.

Bruce S.

Re: dialog dbcombo looping

Posted: Fri Jan 25, 2013 6:07 pm
by James Bott
Bruce,
I use the "traps for invalid data" because an empty selection always seems to come along with a combobox, which I don't want.
I would just display zero when there is a blank combo (or both combos are blank). Users can easily figure this out.

Using a trap with a popup msgbox you force the user to deal with it physically using the mouse. The better way is to display all messages on the screen then the user can just look at it.

You can accomplish your desired task with two comboboxes, and a Close button as the only user interactions needed.

With interfaces, less is better.

Regards,
James