Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

If program running, don't start it again...


  • Please log in to reply
2 replies to this topic
AHKJeff
  • Members
  • 94 posts
  • Last active: May 01 2016 05:13 PM
  • Joined: 09 Feb 2014

OK I figured out how to not run a program multiple times using an 'If' command.

 

What I would like to know is how to program more efficiently.

That is, if you have 10 lines of code that are the same in the

IfWinExist part and Else part:

 

IfWinExist

{

Do this... and then

. (same code)

.

.

.

etc.

}

else

{

. (same code as above)

.

.

.

}

 

Is there a way to reference the same code, so you don't enter it twice?

TIA



Travis Gibby
  • Members
  • 8 posts
  • Last active: Sep 19 2014 03:22 PM
  • Joined: 21 Aug 2013
You can do this...


IfWinExist
{
Do this... and then
Gosub, Subroutine
etc.
}
else
{
Gosub, Subroutine
}

Subroutine:
Code goes here
.
.
.
Return


Don't forget the "Return" at the end of the subroutine.
You can label it anything you like. You don't have to name it subroutine.

AHKJeff
  • Members
  • 94 posts
  • Last active: May 01 2016 05:13 PM
  • Joined: 09 Feb 2014

Don't forget the "Return" at the end of the subroutine.
You can label it anything you like. You don't have to name it subroutine.

 

 

Cool!

Thanks a lot Travis.

I had tried a Goto but it didn't work. It said it had to be in the same bracket to work.

This is exactly what I was looking for.

 

 

The reason I posted here was because I saw AutoHotKey 'Gaming', Scripts 'Gaming' etc.

Since my post was not about gaming, this was the closest I could find.

I'm still not sure where I should post asking questions about programming AutoHotKey.