Jump to content

If then statements


jonez34
 Share

Recommended Posts

I tried searching the forums for this question as I am sure someone has asked this but I didn't have enough charachthers for the search.

Anyway, I am very new to this (2 hours in fact) and am wondering how do I do an if statment where a Yes anwser will go somewhere an No will quit the script.

I'm thinking of something like

If MsgBox(4,"Blah","Blah") = <this is were I need help>

I need the yes to go to either another line in the script or call another au3 file (haven't decided yet) and the NO to just exit. I think that I need an Else statement but everything that I try gives me an error.

Also since I would like to know, whats the equivilent of the batch files GOTO command in autoit?

I am really looking forward to the anwser as this is a really cool way of doing things.

Link to comment
Share on other sites

There's no longer a GoTo command anymore in the AutoIt language. You can still get similar effect with a loop

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

  • Developers

I tried searching the forums for this question as I am sure someone has asked this but I didn't have enough charachthers for the search.

Anyway, I am very new to this (2 hours in fact) and am wondering how do I do an if statment where a Yes anwser will go somewhere an No will quit the script.

I'm thinking of something like

If MsgBox(4,"Blah","Blah") = <this is were I need help>

I need the yes to go to either another line in the script or call another au3 file (haven't decided yet) and the NO to just exit. I think that I need an Else statement but everything that I try gives me an error.

Also since I would like to know, whats the equivilent of the batch files GOTO command in autoit?

I am really looking forward to the anwser as this is a really cool way of doing things.

Button Pressed Return Value

OK 1

CANCEL 2

ABORT 3

RETRY 4

IGNORE 5

YES 6

NO 7

TRY AGAIN ** 10

CONTINUE ** 11

so

If MsgBox(4,"Blah","Blah") = 6 then
     ; yes
Else
    ; No
EndIF

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

O.k. so below is the script that I am trying to get done.

If MsgBox (4,"Question","Do you have a zip program installed?") = 6 Then MsgBox (0,"what","what")

Else Exit

EndIf

I always get an error when I run it. Also instead of the MsgBox of what and what how would I get it to go to either another line in the script (line 21 for example) or call another au3 file?

Link to comment
Share on other sites

  • Developers

O.k. so below is the script that I am trying to get done.

If MsgBox (4,"Question","Do you have a zip program installed?") = 6 Then MsgBox (0,"what","what")

Else Exit

EndIf

I always get an error when I run it. Also instead of the MsgBox of what and what how would I get it to go to either another line in the script (line 21 for example) or call another au3 file?

That is because you do not use the proper syntax... look at the helpfile to see the options...

If MsgBox (4,"Question","Do you have a zip program installed?") = 6 Then 
   MsgBox (0,"what","what")
Else 
   Exit
EndIf

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thank you JdeB. I tried the help file but it is a little to vague sometimes.

Now above the posts says that I can use the Loop command. How does the loop command send the script to another line in the code?

Edited by jonez34
Link to comment
Share on other sites

  • Developers

Thank you JdeB. I tried the help file but it is a little to vague sometimes.

Nah... there is a difference between vague and not understanding .... :P

Thank you JdeB. I tried the help file but it is a little to vague sometimes.

Now above the posts says that I can use the Loop command. How does the loop command send the script to another line in the code?

I am sure BALA will be happy to elaborate on that .... Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Nah... there is a difference between vague and not understanding .... :D

I am sue BALA will be happy to elaborate on that ....

I'm not quite sure if that's a compliment or insult. So I'll just stare.... :P

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

Anyways, I'm quite into NT Batch Scripting myself so I know what it's like to not have the greatness of the GoTo command *sniff* *sniff*

But we will have to do.

To create a loop in a batch file you probably would have done something liek this:

CODE
:BEGIN

ECHO Hello World!

GOTO BEGIN

For AutoIt you can do something like this:

While 1 = 1
MsgBox(0, "Hello World!", "Hello World!")
WEnd

Hope that helped

By the way, check out my site for awesome batch file programs I've made :P

Edited by BALA
[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

  • Developers

I'm not quite sure if that's a compliment or insult. So I'll just stare.... :P

Why ... didn't you bring up this idea ? :D

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

http://www.autoitscript.com/forum/index.php?showtopic=37770

That may help you in calling for another .au3 file

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

Alright, thats good to know...

It seems that you already have your answer, but here is some more info:
While 1 ;this would be like your label
    MsgBox(0, "", "Hi")
WEnd ;this would be like telling AutoIt to goto the labeloÝ÷ Ù«­¢+Ù]¡¥±Ä(5Í ½à À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí$Ìäí´½¥¹Ñ¼¼Í½µÝ¡É¸ÅÕ½Ðì¤(}ͽµÝ¡É ¤íÑ¡¥Ì¥Ì±¥­¹½Ñ¡ÈÑåÁ½½Ñ¼(5Í   ½à À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí$Ìäí´¬¸ÅÕ½Ðì¤)]¹()Õ¹}ͽµÝ¡É ¤(5Í    ½à À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí$Ìäí´Í½µÝ¡É¸ÅÕ½Ðì¤)¹Õ¹ìôôÐí}ͽµÝ¡É

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

GoTo is the same thing as using a function.... there is absolutely no difference besides the command name, and the fact that functions can also have parameters.

Batch:

ECHO Hello World!
GOTO BEGIN

:BEGIN
ECHO begin has been called.

AutoIt:

MsgBox(0, "Title", "Hello World!")
Begin()

Func Begin()
     MsgBox(0, "Title", "Begin has been called.")
EndFunc

The AutoIt code looks a little more intimidating at first, but the extra parameters can proove to be quite useful over time. Just stick with it, and keep learning.

Edited by dandymcgee

- Dan [Website]

Link to comment
Share on other sites

  • 2 weeks later...

I was looking for the goto command myself. After a few hours of playing with the Func command I was able to make it work. I can see why learing that was important, but I did finally figure out how to create a goto like command. It was prety simple and I could have shot myself for not figureing it out sooner. I tried to use a null variable but AutoIT did not like that.

Curtiss W.

CODE
; Adding a goto like fuction in AutoIT V3.; All you need to do is add a variable early in you program. I am going to call; mine goto1. (Then any where you really need to use a goto command you can just; uase a If Then statement.$goto1 = "1" ;Setting up the goto variableIf $goto1 = "1" Then label_name() ; Change label name to the name you are using.
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...