Sign in to follow this  
Followers 0
pshankland

If, Then, Else, EndIf Error?

6 posts in this topic

I am trying to get a simple form to show and then quit with the OK button but keep getting the following error:

Func OKButton()

Error: "If" statement has no matching "EndIf" statement.

The code I have is:

#include <includes\GUIConstants.au3>

If 1 = 2 Then
    Exit
Else
    Opt("GUIOnEventMode", 1)            ; Change to OnEvent mode
    $frmPatternError = GUICreate("Pattern Error!!", 344, 101, 193, 115)
    $lblLabel1 = GUICtrlCreateLabel("Pattern Does Not Match", 72, 8, 197, 24)
    GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
    $lblLabel2 = GUICtrlCreateLabel("Please contact Prod Eng", 8, 32, 327, 24)
    GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
    $btnOK = GUICtrlCreateButton("OK", 128, 64, 75, 25, 0)
    GUICtrlSetOnEvent($btnOK, "OKButton")
    GUISetState(@SW_SHOW)
    
    While 1
        Sleep(1000)
    WEnd
    
    Func OKButton()
        Exit
    EndFunc
EndIf

nyone help as I can't seem to get this working. I know it should be an easy fix - just can't see it.

Thanks.

Pete.

Share this post


Link to post
Share on other sites



move the function...

Func OKButton()

Exit

EndFunc

OUTSIDE (below or after ) the endif

a function should be all by itself

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Is there anyway I could include a simple form with an Quit button inside the If loop, ie without using a function?

Thanks.

Pete.

Share this post


Link to post
Share on other sites

Why do you want to declare it inside the If statement?

Share this post


Link to post
Share on other sites

Why do you want to declare it inside the If statement?

Simply so that if the first instance isn't true then inform the user of the problem and close the program

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>

If 1 = 2 Then
    Exit
Else
    Opt("GUIOnEventMode", 1)            ; Change to OnEvent mode
    $frmPatternError = GUICreate("Pattern Error!!", 344, 101, 193, 115)
    $lblLabel1 = GUICtrlCreateLabel("Pattern Does Not Match", 72, 8, 197, 24)
    GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
    $lblLabel2 = GUICtrlCreateLabel("Please contact Prod Eng", 8, 32, 327, 24)
    GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
    $btnOK = GUICtrlCreateButton("OK", 128, 64, 75, 25, 0)
    GUICtrlSetOnEvent($btnOK, "OKButton")
    GUISetState(@SW_SHOW)
EndIf

While 1
    Sleep(1000)
WEnd

Func OKButton()
    Exit
EndFunc

Why not just use a msgbox(), though?

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