Jump to content
Sign in to follow this  
cowboy713

Looping if statement, what am I doing wrong?

Recommended Posts

cowboy713

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?

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Kidney

If $i = 2 or $i = 5 or $i = 11 or $i = 16 Then

This.

Also, a short hand to adding an integer to a variable and setting it equal to itself looks like this:

$i += 1

Share this post


Link to post
Share on other sites
JohnOne

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.

Share this post


Link to post
Share on other sites
cowboy713

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

Share this post


Link to post
Share on other sites
water

... 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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  

×