Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Inserting a number in structured text

shane2977
2020-04-24
2020-04-24
  • shane2977 - 2020-04-24

    Hi guys,

    I feel a bit dumb having to ask this but how do I insert a number into my structured text program?

    For example:

    This doesn't work
    PercentBuilt := 100*CutMath.Layer / CurrentData.SetGroupNumber;
    
    This does. OneHundred initialized with 100
    PercentBuilt := OneHundred*CutMath.Layer / CurrentData.SetGroupNumber;
    

    I've been searching for a while but I can't seem to think of a search string that will get my answer. Putting number or value in a programming search brings back all kinds of unrelated stuff.

    Thanks
    Shane

     
  • shane2977 - 2020-04-24

    I got it. The data types were DINT's. It's an Allen Bradley thing. You can operate on data using DINT's in AB but it rounds and drops the decimal. Codesys doesn't like that apparently. When I read your post and saw the REAL values it made me realize my mistake (see what I did there). I had to switch all the variables to REAL.

    Thanks for your help again, super appreciate it :)

     

Log in to post a comment.