Basically, since 0 is a valid integer, I'm trying to come up with an _Integer() function that sets @error if the input is not valid. Such as a string returned from InputBox() but I'd also like it to handle numeric input. Since the new AutoIt3 release has changed Int() not to set @error I need to roll my own.
Here's what I have. I'm just wondering if anyone sees a bug waiting to happen.
$i = _Integer("57.7")
If @error Then
MsgBox(0x1010, "Test", "Int() returned error code: " & @error)
Else
MsgBox(0x1040, "Test", $i & " is a valid Int")
EndIf
Func _Integer($n)
Local $legalChars = "-.0123456789"
If IsString($n) Then
For $x = 1 To StringLen($n)
If Not StringInStr($legalChars, StringLeft($n, 1)) Then
Return SetError(1, 0, 0)
EndIf
Next
EndIf
Return Int(Number($n))
EndFunc ;==>_Integer