Jump to content

Help with If...Then and boolean OR


Recommended Posts

I'm having a problem and I'm mostly certain it's with my If...Then statement below

If you run the code below you will see that $OptStr2 = Test. This assumes you'e made a file named JunkFile on your C drive with the words "This is just a Test!!" in it.

The "If $OptStr2..." line should not get satisifed since $OptStr2 does not satisfy any of the values (Opt01, Opt02, etc,) and the code should then continue on to the "Else" part but it does not.

The "ToolTip ("Opt type found",0,0)" is shown meaning that the code is getting into the "Then" part of the code and not the "Else".

What am I doing wrong with my "If $OptStr2..." line? Any help is appreciated

-----------------------------------------------------------------------------------

Global $Paused

HotKeySet("{ESC}", "Terminate")

HotKeySet("{PAUSE}", "TogglePause")

#Include <Misc.au3>

ToolTip ("Opening JunkFile file",0,0)

$JunkFile = FileOpen ("C:\Junkfile.txt",0) ;Open the junk file

Sleep (1000)

ToolTip ("Reading Opt line in JunkFile",0,0)

$OptLine = FileReadLine ($JunkFile,-1) ;Read the last line of the junk file

Sleep (1000)

ToolTip ("Closing JunkFile file",0,0)

FileClose ($JunkFile) ;close the junk file

Sleep (1000)

ToolTip ("Trim right side of Opt line in JunkFile",0,0)

$OptStr1 = StringTrimRight ($Optline,2) ;Trims the last 2 characters off of $Optline

Sleep (1000)

ToolTip ("Counting characters of Opt line in JunkFile",0,0)

$OptStrLen = StringLen ($OptStr1) ;Counts the number of characters remaining in $OptStr1

Sleep (1000)

ToolTip ("Trim left side of Opt line in JunkFile",0,0)

$OptStr2 = StringTrimLeft ($OptStr1,$OptStrLen - 4) ;Trims $OptStr1 leaving just the last 4 characters

Sleep (1000)

ToolTip("Requested Opt is " & $OptStr2,0,0)

Sleep (2000)

SplashOff()

If $OptStr2 = "Opt01" Or "Opt02" Or "Opt03" Or "Opt04" Or "Opt05" Or "Opt06" Or "Opt07" Or "Opt08" Or "Opt09" Or _

"Opt10" Or "Opt11" Or "Opt12" Or "Opt13" Or "Opt14" Or "Opt15" Then

ToolTip ("Opt type found",0,0)

Sleep (5000)

ToolTip("")

Else

ToolTip ("Opt type not found, calling GetOpt again",0,0)

Sleep (5000)

ToolTip("")

EndIf

Func TogglePause () ;Pause function to pause/unpause the program

$Paused = NOT $Paused

While $Paused

Sleep (100)

ToolTip ('Script is "Paused"',0,0)

WEnd

ToolTip ("")

EndFunc

Func Terminate () ;Terminate function to quit the program

Exit 0

EndFunc

-----------------------------------------------------------------------------------

Link to comment
Share on other sites

I believe this will work but not sure it's the best way =/

If $OptStr2 = "Opt01" Or $OptStr2 =  "Opt02" Or $OptStr2 =  "Opt03" Or $OptStr2 =  "Opt04" Or $OptStr2 =  "Opt05" Or $OptStr2 =  "Opt06" Or $OptStr2 =  "Opt07" Or $OptStr2 =  "Opt08" Or $OptStr2 =  "Opt09" Or _
$OptStr2 = "Opt10" Or $OptStr2 = "Opt11" Or $OptStr2 = "Opt12" Or $OptStr2 = "Opt13" Or $OptStr2 = "Opt14" Or $OptStr2 = "Opt15" Then
Link to comment
Share on other sites

Another good way to present such a list of matches:

Switch $OptStr2
    Case "Opt01", "Opt02", "Opt03", "Opt04", "Opt05", "Opt06", "Opt07", "Opt08", _
            "Opt09", "Opt10", "Opt11", "Opt12", "Opt13", "Opt14", "Opt15"

        _Match_Functions()

    Case Else

        _No_Match_Functions()
EndSwitch

There is also this method:

$sMatches = ",Opt01,Opt02,...,Opt14,Opt15,"
If StringInStr($sMatches, "," & $OptStr2 & ",") Then
    _Match_Functions()
Else
    _No_Match_Functions()
EndIf

And then, for the RegExp freaks out there (you know who you are):

If StringRegExp($OptStr2, "(?i)Opt\d{2}", 0) Then
    _Match_Functions()
Else
    _No_Match_Functions()
EndIf

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...