[Help] [Simple] If else / While

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Pazago
Posts: 3
Joined: 15 Mar 2017, 06:25

[Help] [Simple] If else / While

15 Mar 2017, 06:32

Hey :)

I'm pretty new with AHK and just finding my way to it. I have read myself through this forum and the website of Autohotkey but I can't figure out what the problem with my code is.
I can compile it but when I want to excecute it a get this Error Message:
Line 1 (File E "E..... my pfad):

Error: Unknown function name.

Here is my code:

Code: Select all

abc = 1

while abc > 51

   If (abc > 50) Then
	  SEND("b")
	  a = a++

   Else
	  SEND("c")
	  a = a++

   EndIf
WEnd
Thanks a lot
Paz
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: [Help] [Simple] If else / While

15 Mar 2017, 07:42

While .. Wend is syntax for AutoIt3 and Basic. In AHK use While { ;statements } the same way you would bracket a multi-statement If block
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
User avatar
aztec3
Posts: 177
Joined: 07 Apr 2014, 12:05

Re: [Help] [Simple] If else / While

15 Mar 2017, 07:51

I think you have some failed logic, as well as mis-coding, here's a revision of your code (changed the increment to be by 1 and changed the > to < and Send to MsgBox so you can see the results:

Code: Select all

abc = 1
MsgBox,,,abc = %abc%
while abc < 51
	{
		If (abc < 50)
			{
				MsgBox,,, ("b") abc = %abc%
				abc +=1
			}
		Else
			{
				MsgBox,,, ("c") abc = %abc%
				abc +=1
				
				
			}
	}
return
Last edited by aztec3 on 15 Mar 2017, 07:52, edited 1 time in total.
Pazago
Posts: 3
Joined: 15 Mar 2017, 06:25

Re: [Help] [Simple] If else / While

15 Mar 2017, 09:31

Thank you for all your fast feedback! :)

@aztec3 When I'm trying to copy and paste your code in my Editor I get the following Error message:

Line 2 ("Path"...):

MsgBox,,,abc = %abc%
MsgBox,,,abc = ^ ERROR

Error:

Any idear why this is?


Thanks a lot :)
User avatar
aztec3
Posts: 177
Joined: 07 Apr 2014, 12:05

Re: [Help] [Simple] If else / While

15 Mar 2017, 09:42

Pazago, don't why you get that error, I tested it first. You can just comment/delete out that line.

Yup, just tested it again, works for me...anyone else want to verify?
Guest

Re: [Help] [Simple] If else / While

15 Mar 2017, 09:59

@Pazago

Are you 100% sure you are using AutoHotkey and not AutoIt by mistake? The two are somewhat related but incompatible - if you have questions about AutoIt you should ask them over there https://www.autoitscript.com/forum/

If you want to make the switch - welcome! - start here https://autohotkey.com/docs/Tutorial.htm to learn the basics. I suspect you found some code and want to change it, in that case you have found AutoIt code not AutoHotkey code.
Pazago
Posts: 3
Joined: 15 Mar 2017, 06:25

Re: [Help] [Simple] If else / While

15 Mar 2017, 11:58

ohh Wow yeah you are right :o That is a little bit akward, I did a simple autIt skript but informed myself on the Autohotkey page so no wonder nothing works...

Thanks a lot!!

Is there a main differnce between autoIt and autohotkey?
Pretty new to both so doesn't care what I start learning --> My goal ist just pressing some buttons in a specific window :)

Thanks a lot again!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: apeironn, Descolada, Google [Bot] and 197 guests