Jump to content

Recommended Posts

Posted

How do you find if a number is odd or even more elegantly than:

If StringInStr("13579",StringRight($num,1)) Then ;odd/even test - check last digit

MsgBox(0,"Odd",$num)

Else

MsgBox(0,"Even",$num)

EndIf

Thanks

Posted (edited)

See the example of Mod() in the helpfile.

Edited by Siao

"be smart, drink your wine"

Posted

Used this one a while back-

Func IsEven($numner)
    If ($numner/2)=Round($numner/2) Then 
        Return True
    Else
        Return False
    EndIf
EndFunc

How about

Func IsEven($number)

return Mod($number,2) = 0

endfunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Posted

See the example of Mod() in the helpfile.

How about

Func IsEven($number)

return Mod($number,2) = 0

endfunc

I know this works also. You can even use

func IsEven($i)
    Return ($i/2)=Round($i/2)
EndFunc
if you wanted fewer lines. It's just mentioning another way of doing it.

This was the method I used once when coding on systems that didn't have a mod() operator in the lanauge...hum how barbaric...

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
  • Recently Browsing   0 members

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