I don’t know what Scan is but it is interpreted as a keyword if you remove it from ScanScreen, your code will probably work.
Code: Select all
^q::Screen(930,430,960,460)
Screen(x1="", y1="", x2="", y2="") {
x1 += 9 ; These are adjustments to the area, the script I use to find my x/y coordinates is off by 9 pixels for both x and y.
y1 += 9
x2 += 9
y2 += 9
if(x2 = 9 || y2 = 9){
MouseMove, %x2%, %y2%
} else {
MouseMove, %x1%, %y1%
x := x1
y := y1
loop {
if(x = x2) {
break
} else if(y = y2){
x += 1
y := y1
} else {
y += 1
MouseMove, %x%, %y%
sleep, 500
}
}
}
}
Esc::ExitApp
Edit: It seems to assume it is a remap, I’m gussing it’s a key I don’t know, although I could not find it in the key list.
Code: Select all
002: SetKeyDelay,-1
002: Send,{Blind}{ScanScreen(930,430,960,460) DownTemp}
002: Return (0.17)
002: SetKeyDelay,-1
002: Send,{Blind}{ScanScreen(930,430,960,460) Up}
002: Return (1.31)
Edit 2: or just do this.
Code: Select all
^q::
ScanScreen(930,430,960,460)
return
ScanScreen(x1="", y1="", x2="", y2="") {
x1 += 9 ; These are adjustments to the area, the script I use to find my x/y coordinates is off by 9 pixels for both x and y.
y1 += 9
x2 += 9
y2 += 9
if(x2 = 9 || y2 = 9){
MouseMove, %x2%, %y2%
} else {
MouseMove, %x1%, %y1%
x := x1
y := y1
loop {
if(x = x2) {
break
} else if(y = y2){
x += 1
y := y1
} else {
y += 1
MouseMove, %x%, %y%
sleep, 500
}
}
}
}
Esc::ExitApp
And I think your problem is that you are making a function hotkey that takes parameters, to my knowledge the function is called without any parameters when the hotkey is trigured, and the hotkey execution stops with the function meaning the call with parameters is never reached.
Please excuse my spelling I am dyslexic.
Содержание
- Script Error: ELSE with no matching IF
- ELSE with no matching IF, error? :S
- Else with no matching if error, need help
- Error else with no matching if
- [Need Help] Else with no matching IF; IfMsgbox woes.
Script Error: ELSE with no matching IF
I am just starting to use AutoHotKey scripts ..
Can you explain the basic syntax error reported in this test script ..
intended to send Ctrl+C, Ctrl+C or Ctrl+V when *.exe is run
.. where .exe argument %1% = 1 to 3.
I get an error message when running the script.ahk ..
Error: ELSE with no matching IF
- Members
- 278 posts
- Last active: Dec 31 2011 10:53 PM
- Joined: 07 Sep 2004
Your problem seems to come from the «return» commands
not tested but I think that’s OK
- Members
- 21 posts
- Last active: Jul 27 2008 09:33 PM
- Joined: 09 Jun 2005
Thank you .. that works .. sans error message.
On reflection, probably an easier method is to pass two arguments?
- Members
- 278 posts
- Last active: Dec 31 2011 10:53 PM
- Joined: 07 Sep 2004
I think the first option is good. But it’s my own opinion.
- Members
- 26 posts
- Last active: Mar 19 2016 05:59 PM
- Joined: 04 Jun 2005
The problem was caused by the returns, but only while the set of instructions to be excuted for any of the conditions, was not enclosed in braces. These are needed to group the instructions. Without braces, the first return would always return, and the first else would be an orphan.
Although the returns are superfluous as shown by Nemroth, following would have worked:
Источник
ELSE with no matching IF, error? :S
This is the code I’m trying to make for a autologin for the game SRO, the decapcha and everything works just fine, the main problem in the code is in the region labled ;—ImageSearch— , I can’t seem to figure out why «ELSE with no matching IF» error keeps occuring, hopefully a trained eye can spot it. 😆 thanks!
- Administrators
- 2709 posts
- Hates playing Janitor
- Last active: Jan 15 2016 11:37 PM
- Joined: 09 Mar 2008
if statements need < >‘s if there is more then 1 line of code that goes with the if.
rawr. be very afraid
*poke*
. Populate the AutoHotkey city . Pointless but somewhat fun. .
- Members
- 101 posts
- Last active: Jan 22 2010 12:24 AM
- Joined: 13 Apr 2009
- Change Theme
- IP.Board
- IP.Board Mobile
- Ortem
- English (USA)
- English (USA)
- Deutsch
- Privacy Policy
- Help
Источник
Else with no matching if error, need help
Hello,
this is a part of an script that would have to verify the status of an application screen, but I´m getting the Else with no matching if error, where is the error?
What are the mistakes here? because I´m sure there are more than one
Thanks,
- Members
- 726 posts
- Last active: Apr 23 2010 02:50 PM
- Joined: 21 Jul 2008
I went through and properly indented your code. Right off the bat, I noticed one problem.
- Moderators
- 3165 posts
- Last active: Apr 01 2014 01:46 AM
- Joined: 07 Oct 2006
- Guests
- Last active:
- Joined: —
- Guests
- Last active:
- Joined: —
- Members
- 251 posts
- Last active: Jan 28 2015 08:33 PM
- Joined: 08 Dec 2006
- Moderators
- 3622 posts
- Last active: Dec 24 2015 02:21 AM
- Joined: 07 Oct 2006
- Guests
- Last active:
- Joined: —
This is your original code reduced to the minimum and indented
Apart from the mixing of braces/no-braces: If you have another condition, you use else if directly. Else-only is used for the last «anything else case», when you have no conditions left.
Источник
Error else with no matching if
Here is my first program, I had to use a lot of if/ else statements. For some reason the last «else» (bolded) is giving me an error and not letting me run the program. whats going on?
and yes, the if else’s are indented properly, because there are no errors for the first 3 unit types, only for the last one ( ‘F’ ), and i have them all exactly in the same format.
If you want to use multiple statements within an if statement, you need to use braces.
Without braces, you can only have one statement that follows, and you have two right before that bolded else.
PS: Use code tags next time. It’s the <> button to the right ->
Thank you! it worked.
and do the code tags reserve the spacing/ indenting?
To improve your program a bit, make use of the following:
A ShowMenu function, which prints out the options with descriptions.
A switch statement that has a case for each option in the menu, possibly calling a function for each one. the switch also has a default : clause that catches bad input.
Enclose the whole thing in a loop like this:
Branflakes91093 wrote:
If you want to use multiple statements within an if statement, you need to use braces.
In fact, I’d go further: as a matter of good practice, you should always put braces around the code that is executed conditionally, even if it is only a single statement. It is frighteningly easy to introduce bugs by going back and adding a second statement, and forgetting to add the braces. I’ve seen this happen in every single one of the jobs I’ve worked at, and I’ve done it a few times myself.
It’s much safer to protect yourself from this by putting in the braces every time.
Источник
[Need Help] Else with no matching IF; IfMsgbox woes.
Hi everyone, this is day one for me in scripting. I have read the tutorials and searched endlessly on the Msgbox, Else, If/Else and all other related hotlinks in the beginners section. Unfortunately, I have not solved it solo. Here is the script. It keeps telling me the Else line has no matching IF. I can comprend why this is occurring; however, I cannot understand how to implement this with the IFMsgbox command.
Ultimately, I need the script to «Goto» either the «Top» or «Bottom» script depending on how the User inputs their selection.
It should be noted that I copy pasted this first area from http://www.autohotke. ButtonNames.htm and modified it for my own use.
SetTimer, ChangeButtonNames, 50
MsgBox, 4, Eel/Octopus or Hatch/Flycatcher, Which Fish are you turning in?
IfMsgBox, YES
MsgBox, Turning in Eel/Octopus.
Goto, Top
Else,
MsgBox, Turning in Hatchling/Flycatcher.
Goto, Bottom
ChangeButtonNames:
IfWinNotExist, Eel/Octopus or Hatch/Flycatcher
return ; Keep waiting.
SetTimer, ChangeButtonNames, off
WinActivate
ControlSetText, Button1, &Eel/Octopus
ControlSetText, Button2, &Hatch/Fly
return
;Top-Loop: ;**********Top Selection*************
<
;Sleep, 200
;MouseClick, right, xNpc, yNpc ;RIGHT CLICK NPC
;Sleep, 700
;MouseClick, left, xTop, yTop ;Eel or Octopus (Top)
;Sleep, 700
;MouseClick, left, xRep, yRep ;Rep Reward
;Sleep, 700
;MouseClick, left, xFin, yFin ;Finish Button
;Sleep, 700
;MouseClick, left, xClo, yClo ;Close Box via «X»
;Sleep, 700
;Goto, Top
Goto, Start
>
Bottom-Loop: ;**********Bottom Selection***********
<
Sleep, 200
MouseClick, right, xNpc, yNpc ;RIGHT CLICK NPC
Sleep, 700
;MouseClick, left, xBot, yBot ;Hatchling or Flycatcher (Bottom)
;Sleep, 700
;MouseClick, left, xRep, yRep ;Rep Reward
;Sleep, 700
;MouseClick, left, xFin, yFin ;Finish Button
;Sleep, 700
;MouseClick, left, xClo, yClo ;Close Box via «X»
;Sleep, 700
Goto, Bottom
>
::Pause
]::Reload
Esc::ExitApp
Источник
#RequireAdmin
#include <GUIConstantsEx.au3>
#include <Date.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
#include <StaticConstants.au3>
#include <WinAPIProc.au3>
#Include <ScreenCapture.au3>
#include <WinAPI.au3>
#include <Clipboard.au3>
#include <GDIPlus.au3>
Global $sPS, $sPD
Global $iPid, $iTM
Global $Counter = IniRead("Setting.ini","Statistika","Count","0")
Global $GP = IniRead("Setting.ini","GPat","Pat","")
$hGui = GUICreate('Секундомер', 700, 680, -1, -1, -1, $WS_EX_TOPMOST)
Local $btStart = GUICtrlCreateButton('Старт', 392, 8, 75, 25)
Local $sPathSS = GUICtrlCreateInput('', 8, 96, 325, 21)
Local $sPathS = GUICtrlCreateButton('Откуда', 392, 96, 75, 25)
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ProcessClose($iPid)
Exit
Case $sPathS
GUICtrlSetData($sPathSS, '')
$sPS = FileSelectFolder('Выбор копируемой папки', '', 0, '', $hGui)
If Not @error Then GUICtrlSetData($sPathSS, $sPS)
Case $btStart
_GetPath()
EndSwitch
WEnd
Func _GetPath()
Local $GPath1 =IniWrite("Setting.ini","Путь1","Путь",'')
Local $GPath2 =IniWrite("Setting.ini","Путь2","Путь",'')
Local $GPath3 =IniWrite("Setting.ini","Путь3","Путь",'')
Local $GPath4 =IniWrite("Setting.ini","Путь4","Путь",'')
If $GPath1 ='' Then $GPath1 = $sPS
IniWrite("Setting.ini","Путь1","Путь",$sPS)
ElseIf $GPath2 ='' Then $GPath2 = $sPS
IniWrite("Setting.ini","Путь2","Путь",$sPS)
Else $GPath3 ='' Then $GPath3 = $sPS
IniWrite("Setting.ini","Путь3","Путь",$sPS)
EndFunc ;==>_GetPath
- Forum
- General C++ Programming
- ERROR: «else with no matching if»
ERROR: «else with no matching if»
Here is my first program, I had to use a lot of if/ else statements. For some reason the last «else» (bolded) is giving me an error and not letting me run the program. whats going on?
|
|
and yes, the if else’s are indented properly, because there are no errors for the first 3 unit types, only for the last one ( ‘F’ ), and i have them all exactly in the same format.
Last edited on
If you want to use multiple statements within an
if
statement, you need to use braces.
|
|
Without braces, you can only have one statement that follows, and you have two right before that bolded
else
.
PS: Use code tags next time. It’s the <> button to the right ->
Thank you! it worked.
and do the code tags reserve the spacing/ indenting?
Preserve? Yes.
To improve your program a bit, make use of the following:
A ShowMenu function, which prints out the options with descriptions.
A switch statement that has a case for each option in the menu, possibly calling a function for each one. the switch also has a default:
clause that catches bad input.
Enclose the whole thing in a loop like this:
|
|
HTH
Branflakes91093 wrote:
If you want to use multiple statements within an if statement, you need to use braces.
In fact, I’d go further: as a matter of good practice, you should always put braces around the code that is executed conditionally, even if it is only a single statement. It is frighteningly easy to introduce bugs by going back and adding a second statement, and forgetting to add the braces. I’ve seen this happen in every single one of the jobs I’ve worked at, and I’ve done it a few times myself.
It’s much safer to protect yourself from this by putting in the braces every time.
Topic archived. No new replies allowed.
Dmitry5555 0 / 0 / 0 Регистрация: 28.05.2018 Сообщений: 9 |
||||
1 |
||||
20.02.2019, 11:10. Показов 1293. Ответов 2 Метки нет (Все метки)
Выдает ошибки «no matching if»
__________________
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
20.02.2019, 11:10 |
Ответы с готовыми решениями: AVR STUDIO «ошибки» «оформления» При запуске freeradius с ldap и Berkeley DB выдаёт «No matching key/data pair found» Валидатор выдает ошибки (element «header» undefined ) и (end tag for «html» omitted, but OMITTAG NO was specified) Выдаёт ошибки Fatal: Syntax error, «BEGIN» expected but «end of file» found. Пожалуйста посмотрите что не так, прошу! 2 |
Kukuxumushu 1624 / 809 / 146 Регистрация: 13.06.2015 Сообщений: 3,262 |
||||
20.02.2019, 14:27 |
2 |
|||
Сообщение было отмечено Dmitry5555 как решение РешениеDmitry5555, лишние точки с запятой убрать надо. По стандарту Си конструкция
1 |
liv Модератор 5107 / 4538 / 854 Регистрация: 07.10.2015 Сообщений: 9,462 |
||||
20.02.2019, 14:51 |
3 |
|||
Dmitry5555, и не пишите в одну строку… Это ж ужас просто! Сравните:
0 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
20.02.2019, 14:51 |
Помогаю со студенческими работами здесь Написать программу проверки правильности написания сочетаний «жи», «ши», «ча», «ща», «чу», «щу». Исправить ошибки Выдает ошибку — «Не удалось привести тип объекта «TheMaze.FormLevel1» к типу «System.Windows.Forms.Label».» Вот код: Выдает ошибку «использована неинициализированная локальная переменная «flag» » и с переменной «sum_check» та же проблема #include "func.h" //Функция, которая… Комп выдаёт ошибки «Память не может быть read» Искать еще темы с ответами Или воспользуйтесь поиском по форуму: 3 |
I noticed this behaviour and it did not seem very intuitive to me:
This script will generate an error @ line 4 Error: «Else» statement with no matching «If» statement
Global $iTest = 1 If $iTest = 1 Then MsgBox(0, "Debug", "Test was true") ElseIf $iTest = 0 Then MsgBox(0, "Debug", "Test was false") Else MsgBox(0, "Debug", "Test was naughty") EndIf
This script runs without error
Global $iTest = 1 If $iTest = 1 Then MsgBox(0, "Debug", "Test was true") ElseIf $iTest = 0 Then MsgBox(0, "Debug", "Test was false") Else MsgBox(0, "Debug", "Test was naughty") EndIf
So after an If conditional, Then must be followed by a newline, if the conditional statement is to be followed by an ElseIf.
But after an ElseIf conditional, Then does not need to be followed by a newline, even if an Else follows its conditional
This script also runs without error:
Global $iTest = 1 If $iTest = 1 Then MsgBox(0, "Debug", "Test was true") ElseIf $iTest = 0 Then MsgBox(0, "Debug", "Test was false") ElseIf $iTest = 5 Then MsgBox(0, "Debug", "Test was crazy") Else MsgBox(0, "Debug", "Test was naughty") EndIf
But this will cause an error:
Global $iTest = 1 If $iTest = 1 Then MsgBox(0, "Debug", "Test was true") ElseIf $iTest = 0 Then MsgBox(0, "Debug", "Test was false") ElseIf $iTest = 5 Then MsgBox(0, "Debug", "Test was crazy") Else MsgBox(0, "Debug", "Test was naughty") EndIf
Else needs a new line before its statement.
For me it is a little surprising that I must have a newline after the first Then, if I am going to have ElseIf’s following it. Perhaps it would be useful to remove the dependence on the newline?
18 Years Ago
Can anyone expand on why you get this error?
Recommended Answers
You have this kind of statement
if () .......... else .......... else ........
in your code?
Jump to Post
if you have more than one statement in the if/else block you need braces ( { } )
{ toss = 1 + rand() % 2; if(toss == 1 ) { cout << "Heads" << endl; passes = passes +2; } else { cout << "Tails" << …
Jump to Post
You really should sort out a line spacing convention, that just looks horrible.
if{a==1) printf(); else if(a==2) print(); else //do something here otherwise it'll fail.
Jump to Post
All 10 Replies
frrossk
2
Posting Whiz in Training
18 Years Ago
You have this kind of statement
if ()
..........
else
..........
else
........
in your code?
18 Years Ago
You have this kind of statement
if () .......... else .......... else ........
in your code?
{
toss = 1 + rand() % 2;
if
(toss == 1 )
cout << «Heads» << endl;
passes = passes +2;
else
cout << «Tails» << endl;
failure =failure + 1;
}
basically if theres a 1 at int toss then it prints out Heads but i now wish it to add 2 on to passes for every head in printed out, and for every tails i wish for it to +1 to failures.
But i get an illegal error
1o0oBhP
4
Posting Pro in Training
18 Years Ago
if you have more than one statement in the if/else block you need braces ( { } )
{
toss = 1 + rand() % 2;
if(toss == 1 )
{
cout << "Heads" << endl;
passes = passes +2;
}
else
{
cout << "Tails" << endl;
failure =failure + 1;
}
}
18 Years Ago
this can happen only when u had used if statement along with two else which leads to an error……however due to braces u will not get any syntax error but only the logical error is the possiblity
18 Years Ago
Can anyone expand on why you get this error?
You probably have an else statement in your code but no if. It would be nice to see it but what I said above is almost definitly the problem.
18 Years Ago
oops, it looks like 1oo0oobp already told you :O
teoh
0
Newbie Poster
12 Years Ago
if i write a program abt menu of restaurant using if else …exp:if{a==1)
printf(),else
if(a==2)
print()
else…
it give me illegal if else .so how to solve it
12 Years Ago
You really should sort out a line spacing convention, that just looks horrible.
if{a==1)
printf();
else if(a==2)
print();
else
//do something here otherwise it'll fail.
Edited
12 Years Ago
by kirennian because:
n/a
12 Years Ago
If you carefully read about If…else statement then you must know that else is always used for a matching if that means
if(condition)
{block-of-statement;
}
else
{block-of-statement;
}
rules says that this a structure you have to use for if else statement, if you use more then one ELSE for one IF you get this error message.
Check you program your program must have some thing like this
if(condition)
{block-of-statement;
}
else
{block-of-statement;
}
else
{block-of-statement;
}
Best of luck
12 Years Ago
if (condition) //i left a semicolon after the (statement)that’s why i got themessage
{
block-of-statement
}
else
{
block-of-statement;
}
Reply to this topic
Be a part of the DaniWeb community
We’re a friendly, industry-focused community of developers, IT pros, digital marketers,
and technology enthusiasts meeting, networking, learning, and sharing knowledge.