Sign in to follow this  
Followers 0
JonathanChan

Sub-Procedure

4 posts in this topic

Hello...

I'm upgrading from AutoIt 2 to AutoIt 3... I have this script that has this subprocedure that i access using Goto. How would i go about doing it without goto? I don't want to copy and paste this thing in the code 1 dozen times... The code is something like this (except 10x more complicated):

(nevermind the incorrect syntax and incorrect commands of this code... it's just an example... it's like AUT and AU3 code in 1 file... :ph34r: messy... sorry...i don't want to grab the whole thing)..

Do
click, 35, 35
send, etc. etc. etc.
If windowstitle = "bad popup" then goto subprocedure
$test = $test + 1
Until $test = 10

Do
Click, 62,235
send, etc. etc. etc.
If windowstitle = "bad popup" then goto subprocedure
$test = $test + 1
Until $test = 10

:subprocedure
RightClick, 23, 34
etc. etc.
return

This is just an example... but in my real working copy... :subprocedure is like 100 lines and the other parts of the script is much more complicated... Any help much appreciated... Thanks!

Jonathan Chan

Share this post


Link to post
Share on other sites



Hi,

Read the manual about procedures ?

Andre


What about Windows without using AutoIt ?It would be the same as driving a car without an steering Wheel!

Share this post


Link to post
Share on other sites

Autoit 3 have "functions" which you can use instead goto calls which returns into same place. It much more clean and flexible way. For example your pseudo-code will looks like:

Do
click, 35, 35
send, etc. etc. etc.
If windowstitle = "bad popup" then subprocedure ()
$test = $test + 1
Until $test = 10

Do
Click, 62,235
send, etc. etc. etc.
If windowstitle = "bad popup" then subprocedure ()
$test = $test + 1
Until $test = 10

Func subprocedure ()
  RightClick, 23, 34
  etc. etc.
EndFunc

BTW very similar example exists in the very good file located in the Autot folder - AutoIt.chm :ph34r:

Share this post


Link to post
Share on other sites

Autoit 3 have "functions" which you can use instead goto calls which returns into same place. It much more clean and flexible way. For example your pseudo-code will looks like:

BTW very similar example exists in the very good file located in the Autot folder - AutoIt.chm  :ph34r:

<{POST_SNAPBACK}>

Sorry! I was reading the manual and i freaked when Jon said that goto was evil and bad... I thought he got rid of the whole thing altogether... Didn't see anything about procedures... Thanks!

Jonathan Chan

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  
Followers 0