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.
Parents
  • 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

    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

  • Text Item Resource

    Unknown said:
    Is this a intended feature?

    Yes.
    Unknown said:
    This feature is not clear in the MDL programer Guide

    From the MDL Programmers Guide for a Text Item …

    FieldDescription
    formatToDisplay A sprintf format string to convert the value of the variable specified by accessStr to a string. Usually, the `-' flag character should indicate left justification. For example, %-d left-justifies an integer. Use %w to display the variable as a working units string
    formatToInternal A sscanf format string to convert from the text item's string value to the format expected by the variable specified by accessStr
    Interpretation of item contentsformatToInternal value
    integer "%ld"
    floating point number "%lf"
    working units number "%w"
    single character "%c"
    string ""

    Unknown said:
    I was really confused

    Don't worry: confusion is a normal state for MDL programmers 8-)

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

Reply
  • Text Item Resource

    Unknown said:
    Is this a intended feature?

    Yes.
    Unknown said:
    This feature is not clear in the MDL programer Guide

    From the MDL Programmers Guide for a Text Item …

    FieldDescription
    formatToDisplay A sprintf format string to convert the value of the variable specified by accessStr to a string. Usually, the `-' flag character should indicate left justification. For example, %-d left-justifies an integer. Use %w to display the variable as a working units string
    formatToInternal A sscanf format string to convert from the text item's string value to the format expected by the variable specified by accessStr
    Interpretation of item contentsformatToInternal value
    integer "%ld"
    floating point number "%lf"
    working units number "%w"
    single character "%c"
    string ""

    Unknown said:
    I was really confused

    Don't worry: confusion is a normal state for MDL programmers 8-)

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

Children
No Data