Jump to content

Looping if statement, what am I doing wrong?


Recommended Posts

Hello everyone. I just started working with Autoit about a week ago and I only have a a minor amount of coding experience but so far I think it's coming along pretty well. Anyway I'm trying to write a loop and within it there will be an if statement called but I can't seem to figure out what I'm doing wrong. Currently whenever I run it it doesn't seem to ever get past the first If condition.

Local $i = 0
While $i<20
If $i == 2 or 5 or 11 or 16 Then
_Func1()
Else
_Func2()
$i= $i + 1
EndIf
WEnd

I had also tried using a do until and just setting it to Until $i==20 but that was unsuccessful as well. Any idea where I'm messing this up?

Link to comment
Share on other sites

Your code shouldn't ever pass the syntax check because your if statement is wrong.You need to dig into the AutoIt language before writing scripts. Check the Wiki for some very good tutorials.

I think what you need is something liek this:

Local $i = 0
While $i < 20
    If $i = 2 Or $i = 5 Or $i = 11 Or $i = 16 Then
        _Func1()
    Else
        _Func2()
    EndIf
    $i = $i + 1
WEnd

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I'd probably do it something like this...

Local $i = 0
While $i < 20
Switch $i
  Case 2, 5, 11, 16
   _Func1()
  Case Else
   _Func2()
EndSwitch
$i = $i + 1
WEnd
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Figured it would be a simple mistake I was making >.<

Since every seems to be quite active hopefully you could answer one other quite question. I was reading through the different Autoit language references for example of what I was trying to do. With something like

Local $i = 0
While $i <= 10
    MsgBox(0, "Value of $i is:", $i)
    $i = $i + 1
WEnd

for example, what else would I need to put into SciTE to be able to run and test that? Originally I was trying to test my previous code using just MsgBoxes instead of calling the functions to make everything simpler. But the code I just posted I can't seem to run a quick test. Would I need to add in an active function window or a function for the MsgBoxes ?

Thanks for the quite replies, you guys are on the ball considering how early it still is lol.

Edit: Had been trying F5, turned out the reason it wasn't working was since I hadn't bothered to save it since it was just a quick test... Oh man. Thanks for the help again though guys.

Edited by cowboy713
Link to comment
Share on other sites

... what else would I need to put into SciTE to be able to run and test that? ...

Press F5 in SciTE?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...