Sign in to follow this  
Followers 0
muzle6074

'If' statement problems again!

7 posts in this topic

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.

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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-EndSelect

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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-EndSelect

Jos

I'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

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