writerturtle

Else is closing previous Case

8 posts in this topic

When I remove the commented Else statement, I get a number of errors. Tidy tells me "Else is closing previous Case" and I get a ton of syntax errors as well. I can't seem to use an else, or elseif statement no matter how I switch things around. I suspect that it might have to do with my long If And Or string for the $OkayButton, but similarly I don't know how to make that work otherwise.

Basically there are two fields, $OriginalInput and $ShortcutInput that both need to not be null and direct to a real directory, in which case the program will continue. Any help is appreciated.

 

While 1
    $nMsg = GUIGetMsg()
    Select

        Case $nMsg = $GUI_EVENT_CLOSE
            Exit

        Case $nMsg = $OkayButton
            If GUICtrlRead($ShortcutInput) = "" Or GUICtrlRead($OriginalInput) = "" Or FileExists(GUICtrlRead($ShortcutInput)) = False Or FileExists(GUICtrlRead($OriginalInput)) = False Then MsgBox($MB_SYSTEMMODAL, "Error", ("Something went wrong. Please select a valid directory."))
;Else If MsgBox($MB_SYSTEMMODAL, "Good", ("All is good."))
        Case $nMsg = $ShortcutBrowse
            $txt = FileSelectFolder("Open", "C:\")
            GUICtrlSetData($ShortcutInput, $txt)

        Case $nMsg = $OriginalBrowse
            $txt = FileSelectFolder("Open", "C:\")
            GUICtrlSetData($OriginalInput, $txt)

    EndSelect
WEnd

 

Share this post


Link to post
Share on other sites



If GUICtrlRead($ShortcutInput) = "" Or GUICtrlRead($OriginalInput) = "" Or FileExists(GUICtrlRead($ShortcutInput)) = False Or FileExists(GUICtrlRead($OriginalInput)) = False Then
    MsgBox($MB_SYSTEMMODAL, "Error", ("Something went wrong. Please select a valid directory."))
Else
    MsgBox($MB_SYSTEMMODAL, "Good", ("All is good."))
Endif

 

1 person likes this

Share this post


Link to post
Share on other sites
13 minutes ago, RTFC said:

If GUICtrlRead($ShortcutInput) = "" Or GUICtrlRead($OriginalInput) = "" Or FileExists(GUICtrlRead($ShortcutInput)) = False Or FileExists(GUICtrlRead($OriginalInput)) = False Then     MsgBox($MB_SYSTEMMODAL, "Error", ("Something went wrong. Please select a valid directory.")) Else     MsgBox($MB_SYSTEMMODAL, "Good", ("All is good.")) Endif

This fixes the problem exactly! I have spent hours on this! And I thought I got it, except I tried altering the code a little to see if I really got it and I clearly don't. If I split that long line into two separate messages, I get the exact same error codes as before:

 

Case $nMsg = $OkayButton
            If GUICtrlRead($ShortcutInput) = "" Or GUICtrlRead($OriginalInput) = "" Then MsgBox($MB_SYSTEMMODAL, "Error", ("Please select a two directories."))

        ElseIf FileExists(GUICtrlRead($ShortcutInput)) = False Or FileExists(GUICtrlRead($OriginalInput)) = False Then MsgBox($MB_SYSTEMMODAL, "Error", ("Something went wrong. Please select a valid directory."))

        Else MsgBox($MB_SYSTEMMODAL, "Good", ("All is good."))
        EndIf

What do I keep doing wrong?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Case $nMsg = $OkayButton
    If GUICtrlRead($ShortcutInput) = "" Or GUICtrlRead($OriginalInput) = "" Then
        MsgBox($MB_SYSTEMMODAL, "Error", ("Please select a two directories."))
    ElseIf FileExists(GUICtrlRead($ShortcutInput)) = False Or FileExists(GUICtrlRead($OriginalInput)) = False Then
        MsgBox($MB_SYSTEMMODAL, "Error", ("Something went wrong. Please select a valid directory."))
    Else
        MsgBox($MB_SYSTEMMODAL, "Good", ("All is good."))
    EndIf

 

Edited by Jos
1 person likes this

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
9 minutes ago, Jos said:
Case $nMsg = $OkayButton
    If GUICtrlRead($ShortcutInput) = "" Or GUICtrlRead($OriginalInput) = "" Then
        MsgBox($MB_SYSTEMMODAL, "Error", ("Please select a two directories."))
    ElseIf FileExists(GUICtrlRead($ShortcutInput)) = False Or FileExists(GUICtrlRead($OriginalInput)) = False Then
        MsgBox($MB_SYSTEMMODAL, "Error", ("Something went wrong. Please select a valid directory."))
    Else
        MsgBox($MB_SYSTEMMODAL, "Good", ("All is good."))
    EndIf

 

Again, that works perfectly, but this time I can't even see what you changed from my version...

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

4 minutes ago, writerturtle said:

but this time I can't even see what you changed from my version

Are you sure you looked at it carefully? I added some Then words and separated the ElseIF ... Then and Else statement from their next statement, putting it on its own line.
Format is everything! ;)

Jos  

Edited by 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
1 minute ago, Jos said:

Are you sure you looked at it carefully? I added some Then words and separated the ElseIF ... Then statement for the next statement, putting it on its own line.
Format is everything! ;)

Jos  

I have been scripting in AutoIt for three days now and I didn't know until just now that lines mattered like that. There are no markers for the end of lines so I didn't think it mattered (like in C# you have to end every line of code in a semicolon).

I saw that you did that, but I thought you were just making the code tidy. 

Thanks so much for the help!

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