kevinalberts,
Welcome to the AutoIt forums.
Here is my take on a "clamp" function: - @extended shows whether the passed value has been "clamped":
For $i = 1 To 20
ConsoleWrite(_Clamp($i, 5, 15) & " - " & @extended & @CRLF)
Next
Func _Clamp($iValue, $iMin, $iMax)
Local $fClamp = False
If $iValue < $iMin Then
$iValue = $iMin
$fClamp = True
ElseIf $iValue > $iMax Then
$iValue = $iMax
$fClamp = True
EndIf
Return SetError(0, $fClamp, $iValue)
EndFunc
I have left @error alone so you can do some initial checking on the passed value to see if it meets your requirements.
M23