muzle6074 Posted July 10, 2008 Share Posted July 10, 2008 I had an embarrassing problem with this 'If' statement yesterday, it was a spelling mistake. However this 'If' statement has randomly stopped working today and the splash screens says "Subscript used with non-array variable" but it was working yesterday! I hope this isn't another silly spelling mistake muttley $winState = WinGetPos($win); 1032 * 795 If $winState[2] <> 1032 Or $winState[3] <> 795 Then MsgBox(16, "Counter", "Error validating " & $win) Exit ElseIf @error Then MsgBox(16, "Counter", "Failed to detect " & $win & " window") Exit Else WinActivate($win) WinWaitActive($win) EndIf Regards. Link to comment Share on other sites More sharing options...
DMEE Posted July 10, 2008 Share Posted July 10, 2008 The error indicates that the array $winstate does not contain a second or third index. The random part you describe makes it hard to make a good hypothesis of where the bug is. You can try to debug by displaying the array before the IF-statement In the beginning there was nothing and then even that exploded - anonymous Link to comment Share on other sites More sharing options...
muzle6074 Posted July 10, 2008 Author Share Posted July 10, 2008 Thanks for the quick response DMEE. It appears if the window doesn't exist then the script errors. So I need to move my @error to be the first condition. Link to comment Share on other sites More sharing options...
DMEE Posted July 10, 2008 Share Posted July 10, 2008 Happy that you could solve the problem this way btw you're welcome In the beginning there was nothing and then even that exploded - anonymous Link to comment Share on other sites More sharing options...
aslani Posted July 10, 2008 Share Posted July 10, 2008 Thanks for the quick response DMEE. It appears if the window doesn't exist then the script errors. So I need to move my @error to be the first condition. I personally do not like using ...ElseIf..., I rather separate the statements than to ...ElseIf... them together. Since if the condition is not met, it will go on to the next command anyway just like an ...Else..., so I never use ...ElseIf..., I just find it more confusing using it. $winState = WinGetPos($win); 1032 * 795 If @error Then MsgBox(16, "Counter", "Failed to detect " & $win & " window") Exit EndIf If $winState[2] <> 1032 Or $winState[3] <> 795 Then MsgBox(16, "Counter", "Error validating " & $win) Exit Else WinActivate($win) WinWaitActive($win) EndIf [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version Link to comment Share on other sites More sharing options...
Developers Jos Posted July 10, 2008 Developers Share Posted July 10, 2008 I personally do not like using ...ElseIf..., I rather separate the statements than to ...ElseIf... them together. Since if the condition is not met, it will go on to the next command anyway just like an ...Else..., so I never use ...ElseIf..., I just find it more confusing using it.Not sure I understand what you are trying to say here but two If-EndIF's act different than If-ElseIF-EndIf. An If-ElseIf-ElseIF-Else-EndIf is actually the same as a Select-Case-Case-Case Else-EndSelectJos 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 More sharing options...
aslani Posted July 10, 2008 Share Posted July 10, 2008 Not sure I understand what you are trying to say here but two If-EndIF's act different than If-ElseIF-EndIf. An If-ElseIf-ElseIF-Else-EndIf is actually the same as a Select-Case-Case-Case Else-EndSelectJosI'm talking about specifically on his situation. If I'd check for error, I'll put it on it's own If statement specially if the code will terminate if the condition is true, rather than nesting it in an If-ElseIf-EndIf statement.Sorry for being vague. [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now