Jump to content

Why do I have to invert some of my logic statements to get them to work?


rcmaehl
 Share

Go to solution Solved by Danp2,

Recommended Posts

Hi all,

I've had this question for a while. For some reason, on occasion, I will have to invert a logic statement for it to work. The most recent is the below:

Global $aEdges[6] = [5, _
    "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", _
    "C:\Program Files (x86)\Microsoft\Edge Beta\Application\msedge.exe", _
    "C:\Program Files (x86)\Microsoft\Edge Dev\Application\msedge.exe", _
    @LocalAppDataDir & "\Microsoft\Edge SXS\Application\msedge.exe"]

$aEdges[5] = "C:\ProgramData\ie_to_edge_stub.exe"

Local $aChannels[5] = [True, True, True, True, True]

Test($aChannels)

Func Test(ByRef $aChannels)

    For $iLoop = 1 To $aEdges[0] Step 1
        If $aChannels[$iLoop - 1] Then
            MsgBox(0, "Loop", $iLoop)
            If Not $iLoop = $aEdges[0] Then
                MsgBox(0, "Success", $iLoop)
            Else
                ;;;
            EndIf
        EndIf
    Next
EndFunc

This should produce 9 dialog boxes. Yet it does not. However, if I invert it, it works:

Global $aEdges[6] = [5, _
    "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", _
    "C:\Program Files (x86)\Microsoft\Edge Beta\Application\msedge.exe", _
    "C:\Program Files (x86)\Microsoft\Edge Dev\Application\msedge.exe", _
    @LocalAppDataDir & "\Microsoft\Edge SXS\Application\msedge.exe"]

$aEdges[5] = "C:\ProgramData\ie_to_edge_stub.exe"

Local $aChannels[5] = [True, True, True, True, True]

Test($aChannels)

Func Test(ByRef $aChannels)

    For $iLoop = 1 To $aEdges[0] Step 1
        If $aChannels[$iLoop - 1] Then
            MsgBox(0, "Loop", $iLoop)
            If $iLoop = $aEdges[0] Then
                ;;;
            Else
                MsgBox(0, "Success", $iLoop)
            EndIf
        EndIf
    Next
EndFunc

 

It's comparing Int to Int, is there some weird fuzzy loose typing logic happening I'm not aware of?

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

  • Solution

You should read the help file entry on Operators, specifically the portion on Precedence. I'm unsure why you would want to use Not in this fashion, but you would need to modify your line by wrapping the equals portion in parentheses, like this --

If Not ($iLoop = $aEdges[0]) Then
                MsgBox(0, "Success", $iLoop)
            Else
                ;;;
            EndIf

 

Link to comment
Share on other sites

10 minutes ago, Danp2 said:

You should read the help file entry on Operators, specifically the portion on Precedence. I'm unsure why you would want to use Not in this fashion, but you would need to modify your line by wrapping the equals portion in parentheses, like this --

If Not ($iLoop = $aEdges[0]) Then
                MsgBox(0, "Success", $iLoop)
            Else
                ;;;
            EndIf

 

It just feels like I shouldn't need to wrap the equals portion in parentheses for some reason, like it's unnatural compared to the rest of the language to me. I don't know where I got it from. Maybe AutoIt should add != 😅

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

7 hours ago, rcmaehl said:

Maybe AutoIt should add !=

What about <> ???

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
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
 Share

  • Recently Browsing   0 members

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