Menu

Is maths permissible inline with 'If...Then' statements?

Help
mkstevo
2016-09-29
2016-09-30
  • mkstevo

    mkstevo - 2016-09-29

    Is it possible to check for a range of values using something like:

    If (Value > (MidValue - 10)) and (Value < (MidValue + 10)) Then
    ...
    End If
    

    Assuming it is, would I need to encase my test statements in brackets as the above example, or the example below:

    If Value > (MidValue - 10) and Value < (MidValue + 10) Then
    ...
    End If
    

    Or would I need to do the maths prior to the 'If...Then' as this:

    Let LoValue = MidValue - 10
    Let HiValue = MidValue + 10
    If Value > LoValue and Value < HiValue Then
    ...
    End If
    
     

    Last edit: mkstevo 2016-09-29
  • Anobium

    Anobium - 2016-09-29

    Always play safe.

    LoValue = MidValue - 10
    HiValue = MidValue + 10
    If Value > LoValue and Value < HiValue Then
    ...
    End If
    

    and, no need for LET statements.

     
  • mkstevo

    mkstevo - 2016-09-30

    Thanks for the reply.

    While 'Let' statement is not required in CGB, I find it helps me to focus. I see the 'Let' statement and understand that it is a value assignment, as opposed to a test of equality. It is perhaps a hangover from my Delphi (Object Pascal) time where the symbol for a test of equality was '=' and the symbol for a value assignment was ':='.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.