Number entries are reset to 0.0 automatically.

Hi, There,

I am trying to let the users to enter a number in a text box. My text box definition looks as follows

DItem_TextRsc TEXTID_myNumber  = 
{
NOCMD, LCMD, NOSYNONYM, NOHELP, LHELPCMD, NOHOOK, NOARG,
20,
"%0.2f", "%0.2f", "", "", NOMASK, TEXT_NOCONCAT,
"Road from:",
"myNumber"
};
There is not a hook function associated with it. However, when I enter a number, say 2.5, 
when I tab out of the text box, there display automatically change to 0.0. I am totally confuse with this behaviou.
What did I miss here?
Any suggestion will be greatly appreciated.
Ken
PS: Sorry for the re-posting. Some lines in my previous one were cut short for unknown reasons.
  • You specify an access string myNumber for your text item.  A text item reflects the value of its  access string, and when your user changes text in that text box it changes the value of the access string automatically.

    That happens only if (i)  myNumber is a global variable and (ii) you have published your access string.

     
    Regards, Jon Summers
    LA Solutions

  • Hi, Jon,

    Thanks for your reply. I did all things as setting up the global variable, publish it. However, when I enter a number, the value reset to 0.0 after I move the focus to anther item.

    I thought this would be a simple thing to do. But this strange behavior really confused me. Any suggestion on the potential cause of the resetting the value?

    Thanks,

    Ken

  • Hi, Jon,

    I did a bit digging and found that the trouble maker is the format string "%0.2f". If I change  "%0.2f" to "%f", the value won't be reset. However, the display will not shown with 2 digit after the decimal point. Is this a bug or I did it incorrectly.

    Your help will be greatly appreciated.

    Ken

    1. What is the declaration of myNumber?
    2. Show us a code snippet where you publish your variable(s)

     
    Regards, Jon Summers
    LA Solutions

  • Hi, Jon,

    The myNumber is a part of a structure. It is a float.

    Best Regards,

    Ken

  • Unknown said:
    myNumber is a part of a structure. It is a float

    It's hard to diagnose a problem without seeing the patient.

    Can you show us

    1. the definition of the struct that contains myNumber
    2. the mdlDialog_publishXxx statement where you publish that struct so the Dialog Manager can see it

    Unknown said:
    myNumber is a part of a structure

    Your access string contains myNumber. But, if myNumber is part of a struct , your access string should contain structVariable.myNumber or structVariable->myNumber.  Which to use depends on how you declare & publish your struct.

     
    Regards, Jon Summers
    LA Solutions

  • Hi, Jon,

    Thanks for your reply.

    My data structure is as follows:

    typedef struct tagRsPC

    {   // Pavement central line data structure.

       char St_Name[MAX_TEXT_LEN];

       double Road_from;                  // Chainage at start of street segment

       double Road_to;                     // Chainage at end of street segment

       int Lanes;                       // Number of lanes: 4

       double Seg_length;              // Length between chainages in metres

       char Seal_type[MAX_TEXT_LEN];        // Bitument

       char Treatment[MAX_TEXT_LEN];       // Surfacing

       int Seal_W;                     // Width of payment seal in millimetres

       int Seal_D;                     // depth of payment seal in millimetres

       double Pavement_W;                  // width of pavement in meters

       // More here: base1, base2, base3, sub1, sub2, sub3

       char Base1Type[MAX_TEXT_LEN];   // Asphalt

       int Base1Depth;                 // 25

       char Base2Type[MAX_TEXT_LEN];   // Asphalt

       int Base2Depth;                 // 30

       char Base3Type[MAX_TEXT_LEN];   // Asphalt

       int Base3Depth;                 // 2

       char Sub1Type[MAX_TEXT_LEN];    // Class 1 CR (Crashed Rock)

       int Sub1Depth;                  // 145

       char Sub2Type[MAX_TEXT_LEN];    // Class 3 CR (Crashed Rock)

       int Sub2Depth;                  // 150

       char Sub3Type[MAX_TEXT_LEN];    // Class 4 CR (Crashed Rock)

       int Sub3Depth;                  // 200

       tElementIDs *elIDP;                     // Graphic elment ID;

       ULong  eleId;

       tRsProject *prj;

    }   tRsPavementCentreline;

    The troubled one is     double Road_from;

    My publish statement is:

       mdlDialog_publishComplexVariable(setP, "tagRsPC","uiPavementCentreline", &uiPavementCentreline);

    My resounce definition for double Road_from is

    DItem_TextRsc TEXTID_PC_Road_from =

    {

       NOCMD,    LCMD,    NOSYNONYM,    NOHELP,    LHELPCMD,    NOHOOK, NOARG,

       MAX_TEXT_LEN_DB,

       "%f",    "%f",    "",    "",    NOMASK,    TEXT_NOCONCAT,

       "Road from:",

       "uiPavementCentreline.Road_from"

    };

    If I change the format string from %f to %.2f or %0.2f, the value will be reset to 0.00 after the text item is out of focus.

    Thanks for your kindly help.

    Ken

  • Is it correct to infer that you have declared a global variable like this?

    tRsPavementCentreline uiPavementCentreline;

    What's the #definition of MAX_TEXT_LEN_DB?

    What happens if you temporarily replace "uiPavementCentreline.Road_from" with "12.3456"?

    Here's an example of a working text item that displays a floating-point number:

    DItem_TextRsc TEXTID_Angle  =
        {
        CMD_ACTIVE_ANGLE,
        MCMD,
        NOSYNONYM,
        NOHELP,
        LHELP,
        HOOKITEMID_txt_SetPlotAngle,
        NOARG,
        6,
        "%.1lf",
        "%f",
        "",
        "",
        NOMASK,
        TEXT_CONCAT,
        TXT_tItem_Angle,
        "g_borderVars.placement.plotAngle"
        };

     
    Regards, Jon Summers
    LA Solutions

  • Hi Ken,

    In Textbox item resource specification, you can find it has two format definitions, first is 'formatToDisplay' and second is 'formatToInternal'. You can set first to "%.2f" and second to "%f" for your case.

    HTH,

    Yongan



  • Hi, Yongan,

    Thanks for your help. The suggestion does resolve the problem. Is this a intended feature? This feature is not clear in the MDL programer Guide. If it is intended, I would suggest that it be mentioned in the document. I am not sure about other programmers, I was really confused.

    Thanks again,

    Ken