Jump to content

Else is closing previous Case


Recommended Posts

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

 

Link to comment
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

 

Link to comment
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?

Link to comment
Share on other sites

  • Developers
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

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

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

Link to comment
Share on other sites

  • Developers
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

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

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!

Link to comment
Share on other sites

  • Developers

The helpfile will explain the 2 formats for If..Else--EndIf statements we have. ;)

Jos

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...