Function Reference


_MathCheckDiv

Checks if first number is divisible by the second number

#include <Math.au3>
_MathCheckDiv ( $iNum1 [, $iNum2 = 2] )

Parameters

$iNum1 Integer value to check
$iNum2 [optional] Integer value to divide by (default = 2)

Return Value

Success: $MATH_ISNOTDIVISIBLE (1) for not divisible.
$MATH_ISDIVISIBLE (2) for divisible.
Failure: -1 and sets the @error flag to non-zero if non-integers are entered.

Remarks

This function by default checks if the first number is either odd or even, as the second value is default to 2.

Example

#include <Math.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $iVar = Int(InputBox("Odd or Even", "Enter a number:")) ; Parse as an integer.
    Local $iResult = _MathCheckDiv($iVar, 2) ; Divide the number by 2.
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "You did not enter a valid number")
    Else
        Switch $iResult
            Case -1
                MsgBox($MB_SYSTEMMODAL, "", "You did not enter a valid number")
            Case $MATH_ISNOTDIVISIBLE
                MsgBox($MB_SYSTEMMODAL, "", "Number is odd")
            Case $MATH_ISDIVISIBLE
                MsgBox($MB_SYSTEMMODAL, "", "Number is even")
            Case Else
                MsgBox($MB_SYSTEMMODAL, "", "Could not parse")
        EndSwitch
    EndIf
EndFunc   ;==>Example