Sign in to follow this  
Followers 0
Rogue5099

Even Odd numbers Can I?

15 posts in this topic

I am wanting to run a IniWirte every even or odd number but in a never ending loop (hince Until -1). Somthing like this:

While 1

Do

$a = $a + 1

_Func1()

_Func2()

???If $a = ODDNUMBER Then???

IniWrite(.....)

???If $a = EVENNUMBER Then???

IniWrite(.....)

_Func3()

_Func4()

Sleep(2000)

Until $a = -1

WEnd

All help is apperciated!!!

Share this post


Link to post
Share on other sites



If Mod($a, 2) = 0 Then ;; The number is even


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

If IsInt($a/2) Then...

If IsInt(10/2) Then ?????????

Edit: Oooops. Forget this one.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

If IsInt(10/2) Then ?????????

Sorry about this GEOSoft but I couldn't resist it.

$AdmiralAlkex = 0
$Geosoft = 0
For $n = 1 To 100
    $a = IsInt($n / 2)
    $b = Mod($n, 2) = 0
    If $a <> $b Then
        $Geosoft += 1
    Else
        $AdmiralAlkex += 1
    EndIf

Next

MsgBox(0, "Scores", "AdmiralAlkex has " & $AdmiralAlkex & "%" &@CRLF & "Geosoft has " & $Geosoft & "%")
Edited by martin

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.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

@martin. Your example is flawed. So was my 10/2 example by the way.

$AdmiralAlkex = 0
$Geosoft = 0
For $n = 1 To 100
    If Mod($n, 2) = 0 Then $Geosoft += 1
    If IsInt($n/2) Then $AdmiralAlkex += 1
Next

MsgBox(0, "Scores", "AdmiralAlkex has " & $AdmiralAlkex & "%" &@CRLF & "Geosoft has " & $Geosoft & "%")

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

heh

$number = 122

If Not BitAND($number,1) Then MsgBox(0,"","even number")

muttley


- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

Share this post


Link to post
Share on other sites

heh

$number = 122

If Not BitAND($number,1) Then MsgBox(0,"","even number")

muttley

That works too. So far the OP has 3 methods.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Another solution:

$number=10
If Int($number/2)=$number/2 Then MsgBox(0,"Info",$number&" is even")

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

If IsInt(10/2) Then ?????????

Edit: Oooops. Forget this one.

lol @ GEOSoft muttley

Another solution:

$number=10
If Int($number/2)=$number/2 Then MsgBox(0,"Info",$number&" is even")
What is it with swedes and integers? :)

Share this post


Link to post
Share on other sites

@martin. Your example is flawed. So was my 10/2 example by the way.

$AdmiralAlkex = 0
$Geosoft = 0
For $n = 1 To 100
    If Mod($n, 2) = 0 Then $Geosoft += 1
    If IsInt($n/2) Then $AdmiralAlkex += 1
Next

MsgBox(0, "Scores", "AdmiralAlkex has " & $AdmiralAlkex & "%" &@CRLF & "Geosoft has " & $Geosoft & "%")

Yes that's true, 100% each would be correct! No offence intended.

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.

Share this post


Link to post
Share on other sites

Yes that's true, 100% each would be correct! No offence intended.

When do I take offence? Actually, when do I pay attention? muttley

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

; just to check if $number is not 0
If $number > 0 Then
    If Mod($number, 2) = 1 Then
    ; number is odd
    Else
    ; number is even
    EndIf
EndIf


[center]It's a question of mind over matter, if I don't mind, it doesn't matter.[/center]

Share this post


Link to post
Share on other sites

; just to check if $number is not 0
If $number > 0 Then
    If Mod($number, 2) = 1 Then
    ; number is odd
    Else
    ; number is even
    EndIf
EndIf
No need for that because 0 is an even number and the previous tests would show that.

An integer n is called *even* if there exists an integer m such that n = 2m, and odd if n+1 is even.

Since 0 = 2 * 0 and there is no integer m where 2*m = 0 + 1 then it is even.


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.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0