Change from the PLC code the Text property of a rectangle...

elsabz
2017-01-09
2017-01-17
  • elsabz - 2017-01-09

    Hello everyone, I need to change from the PLC code the Text property of a rectangle.
    To display two decimal i use the following string "% .2f", but I predict that it will also change to three decimal "% .3f".
    Please someone can post a code sample that uses the Visu library?

    Thank You.

     
  • elsabz - 2017-01-16

    perhaps I expressed myself badly, I try to explain it again:

    In one visualization screen i have one rectangle for display one variable value.
    wehn i develop, if i put the text name %.2f , in run mode i see the value with two decimal point.
    The question is: i want switch from code %.2f or %.3f ... is possible? if yes how?
    Second question, this format is possible only for floating point variable or is possible also for integer variable (eg. %.2d)?

    Thanks in advance

     
  • Anonymous - 2017-01-17

    Originally created by: Massimo.Milluzzo

    I think it is not possible to change %.2f into %.3f because this is a design time parameter.

    Integer variables don't have a decimal portion, the '.#' string is ignored. If you want you can create a floating point variable to show. In your routine convert the integer into a float.
    Anyway, why do you want to show an integer as #.00 if it cannot uses decimal values? This could confuse the user

     
  • elsabz - 2017-01-17

    thanks for the reply
    Too bad you can not do
    Perhaps the best way is to use the string?
    By formatting the string in the code and then displays it in a rectangle?

    Zitat:
    Anyway, why do you want to show an integer as #.00 if it cannot uses decimal values? This could confuse the user

    is a programming technique to use integers for display the decimal as is necessary for the application, the use of a float commits more resources, but this would be less important than the ability to change the format of the code and for the user is not understandable.

     
  • Anonymous - 2017-01-17

    Originally created by: Massimo.Milluzzo

    elsabz hat geschrieben:
    is a programming technique to use integers for display the decimal as is necessary for the application, the use of a float commits more resources, but this would be less important than the ability to change the format of the code and for the user is not understandable.

    Ah ok, like in WinCC Flexible.
    A workaround could be to set the 'Text variable' as expression. See the attachment

    is the integer variable to display, is the scale factor. In your situation should be 10,100,1000 etc.

    IMG: Cattura.PNG

     
  • elsabz - 2017-01-17

    Zitat:
    Ah ok, like in WinCC Flexible.

    Yes or Movicon

    ok with expression is cool ... but if you set the text to %f in run i see 6 decimal point

     
  • Anonymous - 2017-01-17

    Originally created by: Massimo.Milluzzo

    You can set the text as %.2f
    The problem is, as far as I know, you cannot modify the number of decimal at runtime

     
  • elsabz - 2017-01-17

    I found the solution to the problem, with the method of the strings %s
    I also managed to improve because I have also introduced the minutes

    // Global Variable
       gvl.Tempo_A: DWORD; //  TIME();
       gvl.testStringa : STRING;
       gvl.testBoleana : BOOL;
    //Function Block
    VAR
       min: STRING;
       sec: STRING;
       cent: STRING;
       mill: STRING;
       x: DWORD;
       a: DWORD;   
       b: DWORD;
       c: DWORD;
    END_VAR
    min := DWORD_TO_STRING(gvl.Tempo_A/60000);
    x := (gvl.Tempo_A / 1000) MOD 60;
    b := x MOD 10;
    a := (x - b) / 10;
    sec := Concat(DWORD_TO_STRING(a), DWORD_TO_STRING(b));
    x := (gvl.Tempo_A MOD 1000) / 10;
    b := (gvl.Tempo_A / 10) MOD 10;
    a := (x - b) / 10; 
    cent := Concat(DWORD_TO_STRING(a),DWORD_TO_STRING(b));
    x := gvl.Tempo_A MOD 1000;
    c := x MOD 10;
    b := (gvl.Tempo_A / 10) MOD 10;
    a := (x - b) / 100; 
    mill := Concat(DWORD_TO_STRING(a), Concat(DWORD_TO_STRING(b), DWORD_TO_STRING(c))); 
    IF gvl.testBoleana THEN
    gvl.testStringa := Concat(Concat(Concat(Concat(min, ':'),sec), '.'), mill);
    ELSE
    gvl.testStringa := Concat(Concat(Concat(Concat(min, ':'),sec), '.'), cent);
    END_IF   
    

    I think this is the only solution if there is another way someone enlighten me

    Thanks ... and good job

    IMG: Test.png

     
  • Anonymous - 2017-01-17

    Originally created by: Massimo.Milluzzo

    Ok, nice solution.

    (Ma sei italiano?)

     
  • elsabz - 2017-01-17

    Si

     

Log in to post a comment.