I have a simple test program ( see posting below) where I take two numeric 
decimal fields and try to multiply their values and show the results on the 
next form.  I keep getting the same resulting value of 4.0000267e

Any help would be great
Here is the code
/******************************************************************************
 *
 * Copyright (c) 1999-2004 PalmSource, Inc. All rights reserved.
 *
 * File: AppMain.c
 *
 *****************************************************************************/

#include <PalmOS.h>

//#include "AppResources.h"
#include "../rsc/AppResources.h"
#include "../rsc/MathLib.h"
  

/***********************************************************************
 *
 *      Entry Points
 *
 ***********************************************************************/
FieldType* field;
        Int32 index;
        MemHandle htext;
        char *ptext;
        
RectangleType theRect;
FlpCompDouble theCompFloat;
char theString[80];
float theFloat1, theFloat2;
        

/***********************************************************************
 *
 *      Internal Constants
 *
 ***********************************************************************/
#define appFileCreator                  'frm1'  // register your own at 
http://www.palmos.com/dev/creatorid/
#define appVersionNum                   0x01
#define appPrefID                               0x00
#define appPrefVersionNum               0x01


/***********************************************************************
 *
 *      Internal Functions
 *
 ***********************************************************************/


/***********************************************************************
 *
 * FUNCTION:    MainFormDoCommand
 *
 * DESCRIPTION: This routine performs the menu command specified.
 *
 * PARAMETERS:  command  - menu item id
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
/*static Boolean MainFormDoCommand(UInt16 command)
{
        Boolean handled = false;
        FormType * pForm;


        switch (command) {
                case MainOptionsAboutStarterApp:
                        pForm = FrmInitForm(AboutForm);
                        FrmDoDialog(pForm);                                     
// Display the About Box.
                        FrmDeleteForm(pForm);
                        handled = true;
                        break;
                        

        }
        
        
        return handled;
}
*/


/***********************************************************************
 *
 * FUNCTION:    MainFormHandleEvent
 *
 * DESCRIPTION: This routine is the event handler for the 
 *              "MainForm" of this application.
 *
 * PARAMETERS:  pEvent  - a pointer to an EventType structure
 *
 * RETURNED:    true if the event has handle and should not be passed
 *              to a higher level handler.
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
static Boolean MainFormHandleEvent(EventType* pEvent)
{
        Boolean         handled = false;
        FormType*       pForm;
        
        

        switch (pEvent->eType) {
                case menuEvent:
                        //return MainFormDoCommand(pEvent->data.menu.itemID);
                        
        case ctlSelectEvent:
                        if (pEvent->data.ctlSelect.controlID == 
kMainFormOKButton)
                        {
                                pForm = FrmGetActiveForm();
                                
                                // get an index to the first text field
                index = FrmGetObjectIndex(pForm,kMainFormFirstValueTxtField);
            
                // get the pointer to our field
                field = FrmGetObjectPtr(pForm, index);
            
                                // Convert a string to a float
                theCompFloat.fd = FlpAToF(FldGetTextPtr(field) );
                theFloat1 = theCompFloat.d;
                
                // get an index to the second text field
                index = FrmGetObjectIndex(pForm,kMainFormSecondValueTxtField);
            
                // get the pointer to our field
                field = FrmGetObjectPtr(pForm, index);
            
                                // Convert second string to a float
                theCompFloat.fd = FlpAToF(FldGetTextPtr(field) );
                theFloat2 = theCompFloat.d;
                

                

                                FrmGotoForm(kResultsForm);
                                FrmHandleEvent(FrmGetActiveForm(), pEvent);
                                handled = true;
                                break;
                        }
                        
                case frmOpenEvent:
                        pForm = FrmGetActiveForm();
                        
                        // allocate our field chunk
                        htext = MemHandleNew(81);
                        if(htext == NULL)
                                return(0);
                                
                        ////////////////////////////////////
                        // set first text fields value
                        //////////////////////////////////
                        // lock the memory, get the pointer
                        ptext = MemHandleLock(htext);
                        
                        // put some text in the field
                        StrCopy(ptext, "hello");
                        
                        // unlock the fields memory
                        MemHandleUnlock(htext);
                        

            // get an index to the first text field
            index = FrmGetObjectIndex(pForm,kMainFormFirstValueTxtField);
            
            // get the pointer to our field
            field = FrmGetObjectPtr(pForm, index);
            
            // set the text
            FldSetTextHandle(field, htext);
            
            // set focus on the intial text field
                        FrmSetFocus(pForm, index);
            
            
                        ///////////////////////////////////////
                        // set second text fields value
                        ///////////////////////////////////     
                        
                        // allocate our field chunk
                        htext = MemHandleNew(81);
                        if(htext == NULL)
                                return(0);
                                
                        // lock the memory, get the pointer
                        ptext = MemHandleLock(htext);
                        
                        // put some text in the field
                        StrCopy(ptext, "world");
                        
                        // unlock the fields memory
                        MemHandleUnlock(htext);
                        
                        // get an index to the second text field
            index = FrmGetObjectIndex(pForm,kMainFormSecondValueTxtField);
            
            // get the pointer to our field
            field = FrmGetObjectPtr(pForm, index);
            
            // set the text
            FldSetTextHandle(field, htext);
            
            
                        
                        FrmDrawForm(pForm);
                        handled = true;
                        break;
                        
                default:
                        break;
                
        }
        
        return handled;
}

static Boolean ResultsFormHandleEvent(EventType* pEvent)
{
        Boolean         handled = false;
        FormType*       pForm;

        switch (pEvent->eType) {
                case menuEvent:
                        //return MainFormDoCommand(pEvent->data.menu.itemID);
                        
        case ctlSelectEvent:
                        if (pEvent->data.ctlSelect.controlID == 
kResultsFormBackButton)
                        {
                                FrmGotoForm(kMainForm);
                                FrmHandleEvent(FrmGetActiveForm(), pEvent);
                                handled = true;
                                break;
                        }
                        
                case frmOpenEvent:
                pForm = FrmGetActiveForm();
                
                // Convert a float to a string
            theCompFloat.d = theFloat1 * theFloat2;
            FlpFToA( theCompFloat.fd, theString );
                
            ////////////////////////////////////
                        // set results text field value
                        //////////////////////////////////
                        
                        // allocate our field chunk
                        htext = MemHandleNew(81);
                        if(htext == NULL)
                                return(0);
                                
                        // lock the memory, get the pointer
                        ptext = MemHandleLock(htext);
                        
                        // put some text in the field
                        StrCopy(ptext, theString);
 
                        //resize field 
                        MemHandleResize(htext, StrLen(ptext)+1);
                        
                        // unlock the fields memory
                        MemHandleUnlock(htext);
                        

            // get an index to the first text field
            index = FrmGetObjectIndex(pForm,kResultsFormResultsTxtField);
            
            // get the pointer to our field
            field = FrmGetObjectPtr(pForm, index);
            
            // set the text
            FldSetTextHandle(field, htext);
            
            // set focus on the intial text field
                        FrmSetFocus(pForm, index);
                
                
                        FrmDrawForm(pForm);
                        handled = true;
                        break;
                        
                default:
                        break;
                
        }
        
        return handled;
}

/***********************************************************************
 *
 * FUNCTION:    AppHandleEvent
 *
 * DESCRIPTION: This routine loads form resources and set the event
 *              handler for the form loaded.
 *
 * PARAMETERS:  event  - a pointer to an EventType structure
 *
 * RETURNED:    true if the event has handle and should not be passed
 *              to a higher level handler.
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
static Boolean AppHandleEvent(EventType* pEvent)
{
        UInt16          formId;
        FormType*       pForm;
        Boolean         handled = false;

        if (pEvent->eType == frmLoadEvent) {
                // Load the form resource.
                formId = pEvent->data.frmLoad.formID;
                
                pForm = FrmInitForm(formId);
                FrmSetActiveForm(pForm);

                // Set the event handler for the form.  The handler of the 
currently
                // active form is called by FrmHandleEvent each time is 
receives an
                // event.
                switch (formId) {
                        case kMainForm:
                                FrmSetEventHandler(pForm, MainFormHandleEvent);
                                break;
                                
                        case kResultsForm:
                                FrmSetEventHandler(pForm, 
ResultsFormHandleEvent);
                                break;

                        default:
                                break;
                }
                handled = true;
        }
        
        return handled;
}


/***********************************************************************
 *
 * FUNCTION:     AppStart
 *
 * DESCRIPTION:  Get the current application's preferences.
 *
 * PARAMETERS:   nothing
 *
 * RETURNED:     Err value errNone if nothing went wrong
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
static Err AppStart(void)
{
        FrmGotoForm(kMainForm);
        return errNone;
}


/***********************************************************************
 *
 * FUNCTION:    AppStop
 *
 * DESCRIPTION: Save the current state of the application.
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
static void AppStop(void)
{
        // Close all the open forms.
        
        
        
        FrmCloseAllForms();
}


/***********************************************************************
 *
 * FUNCTION:    AppEventLoop
 *
 * DESCRIPTION: This routine is the event loop for the application.  
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
static void AppEventLoop(void)
{
        Err                     error;
        EventType       event;

        do {
                EvtGetEvent(&event, evtWaitForever);

                if (SysHandleEvent(&event))
                        continue;
                        
                if (MenuHandleEvent(0, &event, &error))
                        continue;
                        
                if (AppHandleEvent(&event))
                        continue;

                FrmDispatchEvent(&event);

        } while (event.eType != appStopEvent);
}


/***********************************************************************
 *
 * FUNCTION:    PilotMain
 *
 * DESCRIPTION: This is the main entry point for the application.
 *
 * PARAMETERS:  cmd - word value specifying the launch code. 
 *              cmdPB - pointer to a structure that is associated with the 
launch code. 
 *              launchFlags -  word value providing extra information about the 
launch.
 * RETURNED:    Result of launch
 *
 * REVISION HISTORY: 
 *
 *
 ***********************************************************************/
UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
{
        Err error = errNone;
        //Err error1;

        switch (cmd) {
                case sysAppLaunchCmdNormalLaunch:
                        

                        if ((error = AppStart()) == 0) {
                                
                                // make sure MathLib is on the PDA
                                /*error = SysLibFind(MathLibName, &MathLibRef);
               if (error)
                  error = SysLibLoad(LibType, MathLibCreator, &MathLibRef);
                  ErrFatalDisplayIf(error, "Can't find MathLib"); // Just an 
example; handle it gracefully
                  error = MathLibOpen(MathLibRef, MathLibVersion);
                  ErrFatalDisplayIf(error, "Can't open MathLib");               
        
                                */
                                AppEventLoop();
                                AppStop();
                        }
                        break;

                default:
                        break;
        }
        
        return error;
}



-- 
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/
/******************************************************************************
 *
 * Copyright (c) 1999-2004 PalmSource, Inc. All rights reserved.
 *
 * File: AppMain.c
 *
 *****************************************************************************/

#include <PalmOS.h>

//#include "AppResources.h"
#include "../rsc/AppResources.h"
#include "../rsc/MathLib.h"
  

/***********************************************************************
 *
 *      Entry Points
 *
 ***********************************************************************/
FieldType* field;
        Int32 index;
        MemHandle htext;
        char *ptext;
        
RectangleType theRect;
FlpCompDouble theCompFloat;
char theString[80];
float theFloat1, theFloat2;
        

/***********************************************************************
 *
 *      Internal Constants
 *
 ***********************************************************************/
#define appFileCreator                  'frm1'  // register your own at 
http://www.palmos.com/dev/creatorid/
#define appVersionNum                   0x01
#define appPrefID                               0x00
#define appPrefVersionNum               0x01


/***********************************************************************
 *
 *      Internal Functions
 *
 ***********************************************************************/


/***********************************************************************
 *
 * FUNCTION:    MainFormDoCommand
 *
 * DESCRIPTION: This routine performs the menu command specified.
 *
 * PARAMETERS:  command  - menu item id
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
/*static Boolean MainFormDoCommand(UInt16 command)
{
        Boolean handled = false;
        FormType * pForm;


        switch (command) {
                case MainOptionsAboutStarterApp:
                        pForm = FrmInitForm(AboutForm);
                        FrmDoDialog(pForm);                                     
// Display the About Box.
                        FrmDeleteForm(pForm);
                        handled = true;
                        break;
                        

        }
        
        
        return handled;
}
*/


/***********************************************************************
 *
 * FUNCTION:    MainFormHandleEvent
 *
 * DESCRIPTION: This routine is the event handler for the 
 *              "MainForm" of this application.
 *
 * PARAMETERS:  pEvent  - a pointer to an EventType structure
 *
 * RETURNED:    true if the event has handle and should not be passed
 *              to a higher level handler.
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
static Boolean MainFormHandleEvent(EventType* pEvent)
{
        Boolean         handled = false;
        FormType*       pForm;
        
        

        switch (pEvent->eType) {
                case menuEvent:
                        //return MainFormDoCommand(pEvent->data.menu.itemID);
                        
        case ctlSelectEvent:
                        if (pEvent->data.ctlSelect.controlID == 
kMainFormOKButton)
                        {
                                pForm = FrmGetActiveForm();
                                
                                // get an index to the first text field
                index = FrmGetObjectIndex(pForm,kMainFormFirstValueTxtField);
            
                // get the pointer to our field
                field = FrmGetObjectPtr(pForm, index);
            
                                // Convert a string to a float
                theCompFloat.fd = FlpAToF(FldGetTextPtr(field) );
                theFloat1 = theCompFloat.d;
                
                // get an index to the second text field
                index = FrmGetObjectIndex(pForm,kMainFormSecondValueTxtField);
            
                // get the pointer to our field
                field = FrmGetObjectPtr(pForm, index);
            
                                // Convert second string to a float
                theCompFloat.fd = FlpAToF(FldGetTextPtr(field) );
                theFloat2 = theCompFloat.d;
                

                

                                FrmGotoForm(kResultsForm);
                                FrmHandleEvent(FrmGetActiveForm(), pEvent);
                                handled = true;
                                break;
                        }
                        
                case frmOpenEvent:
                        pForm = FrmGetActiveForm();
                        
                        // allocate our field chunk
                        htext = MemHandleNew(81);
                        if(htext == NULL)
                                return(0);
                                
                        ////////////////////////////////////
                        // set first text fields value
                        //////////////////////////////////
                        // lock the memory, get the pointer
                        ptext = MemHandleLock(htext);
                        
                        // put some text in the field
                        StrCopy(ptext, "hello");
                        
                        // unlock the fields memory
                        MemHandleUnlock(htext);
                        

            // get an index to the first text field
            index = FrmGetObjectIndex(pForm,kMainFormFirstValueTxtField);
            
            // get the pointer to our field
            field = FrmGetObjectPtr(pForm, index);
            
            // set the text
            FldSetTextHandle(field, htext);
            
            // set focus on the intial text field
                        FrmSetFocus(pForm, index);
            
            
                        ///////////////////////////////////////
                        // set second text fields value
                        ///////////////////////////////////     
                        
                        // allocate our field chunk
                        htext = MemHandleNew(81);
                        if(htext == NULL)
                                return(0);
                                
                        // lock the memory, get the pointer
                        ptext = MemHandleLock(htext);
                        
                        // put some text in the field
                        StrCopy(ptext, "world");
                        
                        // unlock the fields memory
                        MemHandleUnlock(htext);
                        
                        // get an index to the second text field
            index = FrmGetObjectIndex(pForm,kMainFormSecondValueTxtField);
            
            // get the pointer to our field
            field = FrmGetObjectPtr(pForm, index);
            
            // set the text
            FldSetTextHandle(field, htext);
            
            
                        
                        FrmDrawForm(pForm);
                        handled = true;
                        break;
                        
                default:
                        break;
                
        }
        
        return handled;
}

static Boolean ResultsFormHandleEvent(EventType* pEvent)
{
        Boolean         handled = false;
        FormType*       pForm;

        switch (pEvent->eType) {
                case menuEvent:
                        //return MainFormDoCommand(pEvent->data.menu.itemID);
                        
        case ctlSelectEvent:
                        if (pEvent->data.ctlSelect.controlID == 
kResultsFormBackButton)
                        {
                                FrmGotoForm(kMainForm);
                                FrmHandleEvent(FrmGetActiveForm(), pEvent);
                                handled = true;
                                break;
                        }
                        
                case frmOpenEvent:
                pForm = FrmGetActiveForm();
                
                // Convert a float to a string
            theCompFloat.d = theFloat1 * theFloat2;
            FlpFToA( theCompFloat.fd, theString );
                
            ////////////////////////////////////
                        // set results text field value
                        //////////////////////////////////
                        
                        // allocate our field chunk
                        htext = MemHandleNew(81);
                        if(htext == NULL)
                                return(0);
                                
                        // lock the memory, get the pointer
                        ptext = MemHandleLock(htext);
                        
                        // put some text in the field
                        StrCopy(ptext, theString);
 
                        //resize field 
                        MemHandleResize(htext, StrLen(ptext)+1);
                        
                        // unlock the fields memory
                        MemHandleUnlock(htext);
                        

            // get an index to the first text field
            index = FrmGetObjectIndex(pForm,kResultsFormResultsTxtField);
            
            // get the pointer to our field
            field = FrmGetObjectPtr(pForm, index);
            
            // set the text
            FldSetTextHandle(field, htext);
            
            // set focus on the intial text field
                        FrmSetFocus(pForm, index);
                
                
                        FrmDrawForm(pForm);
                        handled = true;
                        break;
                        
                default:
                        break;
                
        }
        
        return handled;
}

/***********************************************************************
 *
 * FUNCTION:    AppHandleEvent
 *
 * DESCRIPTION: This routine loads form resources and set the event
 *              handler for the form loaded.
 *
 * PARAMETERS:  event  - a pointer to an EventType structure
 *
 * RETURNED:    true if the event has handle and should not be passed
 *              to a higher level handler.
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
static Boolean AppHandleEvent(EventType* pEvent)
{
        UInt16          formId;
        FormType*       pForm;
        Boolean         handled = false;

        if (pEvent->eType == frmLoadEvent) {
                // Load the form resource.
                formId = pEvent->data.frmLoad.formID;
                
                pForm = FrmInitForm(formId);
                FrmSetActiveForm(pForm);

                // Set the event handler for the form.  The handler of the 
currently
                // active form is called by FrmHandleEvent each time is 
receives an
                // event.
                switch (formId) {
                        case kMainForm:
                                FrmSetEventHandler(pForm, MainFormHandleEvent);
                                break;
                                
                        case kResultsForm:
                                FrmSetEventHandler(pForm, 
ResultsFormHandleEvent);
                                break;

                        default:
                                break;
                }
                handled = true;
        }
        
        return handled;
}


/***********************************************************************
 *
 * FUNCTION:     AppStart
 *
 * DESCRIPTION:  Get the current application's preferences.
 *
 * PARAMETERS:   nothing
 *
 * RETURNED:     Err value errNone if nothing went wrong
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
static Err AppStart(void)
{
        FrmGotoForm(kMainForm);
        return errNone;
}


/***********************************************************************
 *
 * FUNCTION:    AppStop
 *
 * DESCRIPTION: Save the current state of the application.
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
static void AppStop(void)
{
        // Close all the open forms.
        
        
        
        FrmCloseAllForms();
}


/***********************************************************************
 *
 * FUNCTION:    AppEventLoop
 *
 * DESCRIPTION: This routine is the event loop for the application.  
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
static void AppEventLoop(void)
{
        Err                     error;
        EventType       event;

        do {
                EvtGetEvent(&event, evtWaitForever);

                if (SysHandleEvent(&event))
                        continue;
                        
                if (MenuHandleEvent(0, &event, &error))
                        continue;
                        
                if (AppHandleEvent(&event))
                        continue;

                FrmDispatchEvent(&event);

        } while (event.eType != appStopEvent);
}


/***********************************************************************
 *
 * FUNCTION:    PilotMain
 *
 * DESCRIPTION: This is the main entry point for the application.
 *
 * PARAMETERS:  cmd - word value specifying the launch code. 
 *              cmdPB - pointer to a structure that is associated with the 
launch code. 
 *              launchFlags -  word value providing extra information about the 
launch.
 * RETURNED:    Result of launch
 *
 * REVISION HISTORY: 
 *
 *
 ***********************************************************************/
UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
{
        Err error = errNone;
        //Err error1;

        switch (cmd) {
                case sysAppLaunchCmdNormalLaunch:
                        

                        if ((error = AppStart()) == 0) {
                                
                                // make sure MathLib is on the PDA
                                /*error = SysLibFind(MathLibName, &MathLibRef);
               if (error)
                  error = SysLibLoad(LibType, MathLibCreator, &MathLibRef);
                  ErrFatalDisplayIf(error, "Can't find MathLib"); // Just an 
example; handle it gracefully
                  error = MathLibOpen(MathLibRef, MathLibVersion);
                  ErrFatalDisplayIf(error, "Can't open MathLib");               
        
                                */
                                AppEventLoop();
                                AppStop();
                        }
                        break;

                default:
                        break;
        }
        
        return error;
}


Reply via email to