Jump to content
Sign in to follow this  
Zeerti

Simple IF Operator Question

Recommended Posts

Zeerti

How does one make an or statement? I thought it would be '| |' like in most other languages, but I am plum confused and the only thing I could find was the OR operator for logical.  I can't find anything in the help files other than 'OR' which I tried and it of course wants a then statement.

On line 0, what would be the proper way to write that?

if($RegExArray[2] = 'health' OR $RegExArray[2] = 'Health')
    Do
        $Ini_Write=IniWrite("Health.ini","Health",$count,$RegExArray[1])
    Until $Ini_Write>0
    $count+=1
WEnd

Share this post


Link to post
Share on other sites
kylomas

Zeerti,

if $RegExArray[2] = 'health' OR $RegExArray[2] = 'Health' then
    Do
        $Ini_Write=IniWrite("Health.ini","Health",$count,$RegExArray[1])
    Until $Ini_Write>0
    $count+=1
endif



















edit:  Not sure what you are trying to do in your do...until loop, though

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
BrewManNH

You almost have it right.

If ($RegExArray[2] = 'health' Or $RegExArray[2] = 'Health') Then
    Do
        $Ini_Write = IniWrite("Health.ini", "Health", $count, $RegExArray[1])
    Until $Ini_Write > 0
    $count += 1
EndIf

Although, there's no reason to test if it's Health or health, as long as you're using "=" instead of "==".


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Zeerti

So what I am reading is that I just forgot then then statement at the end. I knew it was something simple! Thanks!

As for why I used the or statement I figured it would be case sensitive and since I am having my script pull things out of chat logs I have to be sure that it is still going to run the script if someone types LiKe ThIs instead of Like This.

Share this post


Link to post
Share on other sites
kylomas

And you do not need the parens unless you are using a complex expression like

if ($vara = 1 or $vara = 2) and $varb = 3 then 
    ...
endif

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Zeerti

 

And you do not need the parens unless you are using a complex expression like

if ($vara = 1 or $vara = 2) and $varb = 3 then 
    ...
endif

 

I didn't know this! Good to know. Just a habit from prior programming experience.

Share this post


Link to post
Share on other sites
Zeerti
;Script1 writes
$count=0
While 1
    Sleep(200)
    $FileList = _FileListtoArrayEx('C:****', '*.*', 1)
    $File = $FileList[$FileList[0]]
    ;ConsoleWrite($FileList[$FileList[0]])
    
   ;Opens the file, reads the last line
   $FileHandle = FileOpen($File)
   $LineRead = FileReadLine($FileHandle, -1)
   FileClose($FileHandle)
   
   $RegExArray = StringRegExp($LineRead, ".*?((?i)GSLU).*?(\d+).*?((?i)Health)", 3)
   
   if($RegExArray[2] = 'health' Or $RegExArray[2] = 'Health') Then
      ConsoleWrite($RegExArray[2])
    Do
        $Ini_Write=IniWrite("Health.ini","Health",$count,$RegExArray[1])
    Until $Ini_Write>0
    $count+=1
WEnd

When I try to run this I am getting the following error and I am unsure why: "Z:FOLDERAutoItTest1.au3 (22) : ==> "Wend" statement with no matching "While" statement.:"

Anyone know why?

 

Share this post


Link to post
Share on other sites
kylomas

Your if statement is not closed with endif


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Zeerti

Your if statement is not closed with endif

 

Oh! Haha, Thanks I must have missed it. The WEnd error threw me off.

Though I do have a new issue with it. it's giving me an error that the subscript is being used with a non-Array variable. As you can see in the code  

$RegExArray = StringRegExp($LineRead, ".*?((?i)GSLU).*?(\d+).*?((?i)Health)", 3)

This should set it up to be an array with the Regular Expression assuming it finds one. At the time of testing it isn't appending it to be an array due to it not finding one at the time. What would I need to do to resolve this?

Edited by Zeerti

Share this post


Link to post
Share on other sites
kylomas

Zeerti,

You will need to do some error checking like

if not isarray($RegExArray) then 
    ;
    ; do some $Error routine
    ;
Else
    ;
    ; do array type processing
    ;
endif

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Zeerti

Zeerti,

You will need to do some error checking like

if not isarray($RegExArray) then 
    ;
    ; do some $Error routine
    ;
Else
    ;
    ; do array type processing
    ;
endif

kylomas

 

Thanks again. I'll see what I can figure out before just asking for a resolution

Share this post


Link to post
Share on other sites
BrewManNH

As for why I used the or statement I figured it would be case sensitive and since I am having my script pull things out of chat logs I have to be sure that it is still going to run the script if someone types LiKe ThIs instead of Like This.

As I said before, you're already doing a case insensitive comparison when you use "=", you don't need to test it against different case of the letters unless you use "==" which in AutoIt is used for case sensitve string comparisons. So when you do something like "If $I = "dog"" it won't matter if it's dog, DOG, DoG or any other combination of upper or lower case, the comparison will match.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  

×