Jump to content

_NumIsBetween


Knight
 Share

Recommended Posts

This UDF will check to see if a Variable is between 2 defined numbers.

Success: Returns 1

Failure: Returns 0

Func _NumIsBetween($Var2Test = 0, $MinNumber = 1, $MaxNumber = 1)
    If $Var2Test >= $MinNumber And $Var2Test <= $MaxNumber Then 
        return 1
    Else
        return 0
    EndIf
EndFunc

Test Script:

$x = 5

If _NumIsBetween($x, 0,  10) Then MsgBox(0, "_NumIsBetween Test", "True")

Func _NumIsBetween($Var2Test, $MinNumber, $MaxNumber)
    If $Var2Test >= $MinNumber And $Var2Test <= $MaxNumber Then 
        return 1
    Else
        return 0
    EndIf
EndFunc
Link to comment
Share on other sites

Hm... not bad, but where is the difference in using the UDF instead of the If clause? It's almost the same amount of code. I'm just curious....

If _NumIsBetween($x, 0,  10) Then 
     MsgBox(0, "_NumIsBetween Test", "True")
else
    MsgBox(0, "_NumIsBetween Test", "False")
endif

If $Var2Test >= $MinNumber And $Var2Test <= $MaxNumber Then 
     MsgBox(0, "_NumIsBetween Test", "True")
Else
    MsgBox(0, "_NumIsBetween Test", "False")
EndIf

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Nice, but might I suggest a shorter version?

Func _NumIsBetween($num, $lesser, $greater)
     If $num < $lesser or $num > $greater Then Return 0
     Return 1
EndFunc

Overall pretty good! B)

Link to comment
Share on other sites

@/dev/null

Yep, they are. The reason I made the function is because my current project requires me to check hundreds of variables and see if they are between various combinations of 2 numbers. Rather then making hundreds of If-Then statements, I made the UDF B)

@erifash

Nice Job! I just replaced my UDF with yours in my script!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...