Some Logic help.

Discussion in 'General Discussion' started by Ingo, Apr 3, 2010.

  1. Ingo

    Ingo

    Joined:
    Dec 2, 2006
    Messages:
    290
    Likes Received:
    1
    Location:
    South Africa
    Guys,

    I've been trying to figure out how to do the following:

    I have 4 counters being populated from external (Comfort in this case).
    Counter 1 = 00
    Counter 2 = 09
    Counter 3 = 28
    Counter 4 = 80

    I want to 'append' these into a real number EG. 92880 but seeing that they are not stings I cannot do that.

    I then want to take the result and divide by 1000 to yield the following answer: 92.880. Easy if I can get the step above to work.

    From here it's easy to populate a systemIO variable and display it. The tricky part is how to get Counter values 1 to 4 into a workable format.

    Ingo
     
    Ingo, Apr 3, 2010
    #1
  2. Ingo

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,393
    Likes Received:
    25
    Location:
    Adelaide, South Australia
    Append = addition.

    Well, sort of. I *assume* your counter values will be 00 .. 99.

    So for example, take the number, 98820, and multiply by 100: 9882000, then add the counter value.

    then divide the result by whatever, convert to string.

    I might be missing something here.

    It might be better if you explain the fundamentals - exactly what you are trying to achieve.
     
    ashleigh, Apr 3, 2010
    #2
  3. Ingo

    Ingo

    Joined:
    Dec 2, 2006
    Messages:
    290
    Likes Received:
    1
    Location:
    South Africa
    Thanks Ashleigh, it helps to think outside of the box. Here is my code, it works like a charm. I just need to figure out how to format the output to display only 5 characters max. The following is what I am looking for:

    Value Display
    0.881 0.881
    2.881 2.881
    28.812 28.81
    288.123 288.1

    It must always have 5 characters max.

    <snip>
    CurrentPhase1Byte1 := 01; <- test values
    CurrentPhase1Byte2 := 09;
    CurrentPhase1Byte3 := 28;
    CurrentPhase1Byte4 := 81;

    Result := CurrentPhase1Byte1;
    Result := Result * 100;
    Result := Result + CurrentPhase1Byte2;
    Result := Result * 100;
    Result := Result + CurrentPhase1Byte3;
    Result := Result *100;
    Result := Result + CurrentPhase1Byte4;
    Result := Result / 1000;

    Format(string3,Result:5:3); <- Here I need some help with formatting.

    SetStringSystemIO("Current (Phase 1)", string3);
    <snip>
     
    Ingo, Apr 3, 2010
    #3
  4. Ingo

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,393
    Likes Received:
    25
    Location:
    Adelaide, South Australia
    OK. I don't know the logical string functions all that well, but here is a suggestion:

    Format the converted string to have 3 decimal places. This will give you a string of between 8 and 5 characters in length depending on how big the number is before the ".".

    Then, just truncate the string to 5 characters long, throwing away the right hand side.
     
    ashleigh, Apr 4, 2010
    #4
  5. Ingo

    Ingo

    Joined:
    Dec 2, 2006
    Messages:
    290
    Likes Received:
    1
    Location:
    South Africa
    Done. Works great thanks.

    Ingo
     
    Ingo, Apr 4, 2010
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.