Jump to content
Sign in to follow this  
enigmafyv

How is the AND function used?

Recommended Posts

enigmafyv

Because my words are all less than 4 characters, except for the word 'function', in my title, I'm not able to search for the question I have, so I'm posting, probably, a very common question.

I'm writing a script, and keep in mind I'm a noob, that contains the AND function, however I'm not sure if I'm using it correctly. Could someone please verify whether I'm using it right?

if FileExists(@ProgramFilesDir & "\<folder>\<file.exe>") AND (@ProgramFilesDir & "\<folder>\<file.exe>")
    RunWait(@ProgramFilesDir & "\<folder>\<file.exe>")
    WinWaitActive("<Window Title>","")
        Send("<keystroke(s)>")
    WinWaitActive("<Window Title>","")
        Send("<keystroke(s)>")
EndIf

Share this post


Link to post
Share on other sites
MrBeatnik

AND is just an operator (http://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm).

Your code needs a little tweak:

if FileExists(@ProgramFilesDir & "\<folder>\<file.exe>") AND FileExists(@ProgramFilesDir & "\<folder>\<file.exe>") Then

*forgot the Then!

Edited by MrBeatnik

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites
lev

if FileExists(@ProgramFilesDir & "\<folder>\<file.exe>") AND FileExists(@ProgramFilesDir & "\<folder>\<file.exe>")

RunWait(@ProgramFilesDir & "\<folder>\<file.exe>")

WinWaitActive("<Window Title>","")

Send("<keystroke(s)>")

WinWaitActive("<Window Title>","")

Send("<keystroke(s)>")

EndIf

should be so

Share this post


Link to post
Share on other sites
Valuater

...

If FileExists(@ProgramFilesDir & "\<folder1>\<file1.exe>") And FileExists(@ProgramFilesDir & "\<folder2>\<file2.exe>") Then ; added then
    Run(@ProgramFilesDir & "\<folder1>\<file1.exe>")
    ; changed from RunWait... waits till that prog ends before continuing script
    WinWaitActive("<Window Title>", "")
    Send("<keystroke(s)>")
    WinWaitActive("<Window Title>", "")
    Send("<keystroke(s)>")
EndIf

If FileExists(@ProgramFilesDir & "\<folder1>\<file1.exe>") Or FileExists(@ProgramFilesDir & "\<folder2>\<file2.exe>") Then
    If FileExists(@ProgramFilesDir & "\<folder1>\<file1.exe>") Then RunWait(@ProgramFilesDir & "\<folder1>\<file1.exe>")
    If FileExists(@ProgramFilesDir & "\<folder2>\<file2.exe>") Then RunWait(@ProgramFilesDir & "\<folder2>\<file2.exe>")
EndIf

8)

EDIT; second fileexists()

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
enigmafyv

Because my words are all less than 4 characters, except for the word 'function', in my title, I'm not able to search for the question I have, so I'm posting, probably, a very common question.

I'm writing a script, and keep in mind I'm a noob, that contains the AND function, however I'm not sure if I'm using it correctly. Could someone please verify whether I'm using it right?

if FileExists(@ProgramFilesDir & "\<folder>\<file.exe>") AND (@ProgramFilesDir & "\<folder>\<file.exe>")
    RunWait(@ProgramFilesDir & "\<folder>\<file.exe>")
    WinWaitActive("<Window Title>","")
        Send("<keystroke(s)>")
    WinWaitActive("<Window Title>","")
        Send("<keystroke(s)>")
EndIf

OK, NM, I found out how it works. I just tested it. Man, why didn't I think of that before I posted the question.

The correct way to do this, in case any other noobs are looking for the answer is:

if FileExists(@ProgramFilesDir & "\<folder>\<file.exe>") AND FileExists(@ProgramFilesDir & "\<folder>\<file.exe>") Then

Notice I had to add the FileExists in front of the next param that I was looking for, and I know I entered this incorrectly before, but I had to add the Then function at the end of the line, which was already in my original code, I just forgot it here at the forums.

Hope this helps anyone that needs help with this. Although I have a feeling I'm the only idiot that would post something like this since most people who use AutoIT have some programming experience and would test first and ask questions later. I just got too trigger happy!

All the best...

Share this post


Link to post
Share on other sites
enigmafyv

...

If FileExists(@ProgramFilesDir & "\<folder1>\<file1.exe>") And (@ProgramFilesDir & "\<folder2>\<file2.exe>") Then ; added then
    Run(@ProgramFilesDir & "\<folder1>\<file1.exe>")
    ; changed from RunWait... waits till that prog ends before continuing script
    WinWaitActive("<Window Title>", "")
    Send("<keystroke(s)>")
    WinWaitActive("<Window Title>", "")
    Send("<keystroke(s)>")
EndIf

If FileExists(@ProgramFilesDir & "\<folder1>\<file1.exe>") Or (@ProgramFilesDir & "\<folder2>\<file2.exe>") Then
    If FileExists(@ProgramFilesDir & "\<folder1>\<file1.exe>") Then RunWait(@ProgramFilesDir & "\<folder1>\<file1.exe>")
    If FileExists(@ProgramFilesDir & "\<folder2>\<file2.exe>") Then RunWait(@ProgramFilesDir & "\<folder2>\<file2.exe>")
EndIf

8)

I tried, initially, doing what you have here, without the FileExists in front of the second param, and I was getting a false positive because I would alter the <file2.exe> and it would still come back successful. I had to make sure that the FileExists was also added to the 2nd param and then I didn't get the false positives.

But, hey, thanks for such a quick response. And I like the second approach as well, but it seems to add a bit of extra padding that could be accomplished by the first approach.

Share this post


Link to post
Share on other sites
enigmafyv

Thank you all for being great sports and not ridiculing me for my ignorance, as well as replying so quickly. (MAN I LOVE THIS FORUM, IT'S FULL OF GREAT PEOPLE!)

TTFN

Share this post


Link to post
Share on other sites
Valuater

.. And I like the second approach as well, but it seems to add a bit of extra padding that could be accomplished by the first approach.

please note the "RunWait" replaced by "Run" in the first If statement

and how the "Or" ( demo as info for you ) used the "RunWait"

take another look

.... and Welcome

8)


NEWHeader1.png

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  

×