Knight Posted October 20, 2005 Share Posted October 20, 2005 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 More sharing options...
/dev/null Posted October 20, 2005 Share Posted October 20, 2005 (edited) 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 October 20, 2005 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 More sharing options...
erifash Posted October 20, 2005 Share Posted October 20, 2005 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! My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
Knight Posted October 20, 2005 Author Share Posted October 20, 2005 @/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 @erifash Nice Job! I just replaced my UDF with yours in my script!! Link to comment Share on other sites More sharing options...
LxP Posted October 20, 2005 Share Posted October 20, 2005 Even shorter: Func _NumIsBetween($Num, $Lesser, $Greater) Return ($Num >= $Lesser And $Num <= $Greater) EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now