Sign in to follow this  
Followers 0
williamk

Goto Statements?

9 posts in this topic

Have a little script that is a makeshift search engine. Two things I am trying to do.

1. When the Exit button is clicked, the script should exit.

2. If the User gets the "Number Out of Range" Msg box and clicks on the OK button, I would like to go back to the beginning of the script so the user can either enter a correct number, and/or exit the script.

Way back when, I remember using goto statements to do somethig like this. Can't seem to find that here. Can anyone help?

#include <GUIConstants.au3>

GUICreate("Numerics Search", 320, 120)

$file = GUICtrlCreateInput("", 10, 5, 100, 20, $ES_NUMBER)

GUICtrlSetState(-1, $GUI_NODROPACCEPTED)

GUICtrlSetLimit(-1, 7)

GUICtrlCreateLabel ( "Enter the 7 digit file number you are looking for and press Search.", 10, 30)

GUICtrlCreateLabel ( "NOTE: The Digital Numeric Archive only consists of Auditor File", 10, 50)

GUICtrlCreateLabel ( "Numbers 2430986 - 3170287.", 10, 66)

$btn = GUICtrlCreateButton("Search", 130, 5, 60, 20)

$btn2 = GUICtrlCreateButton("Exit", 130, 90, 60, 20)

GUISetState()

$msg = 0

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

Select

Case $msg = $btn

$FileNumber = GUICtrlRead($file)

ExitLoop

EndSelect

WEnd

If $FileNumber > 3170287 Or $FileNumber < 2430986 Then

MsgBox(4096, "Number Out of Range", "The number must be between 2430986 and 3170287")

Endif

if $FileNumber >= 2430986 And $FileNumber <= 2433260 Then

ShellExecute ("2430986-2433260.pdf")

Endif

;etc

;etc

;etc.....

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

There aren't GOTO commands anymore in AutoIt there are ways to get a similar effect though.

For exit button:

#include <GUIConstants.au3>

_Main() ; starts GUI function

;GUI function
Func Main()
    GUICreate("Numerics Search", 320, 120)
    $file = GUICtrlCreateInput("", 10, 5, 100, 20, $ES_NUMBER)
    GUICtrlSetState(-1, $GUI_NODROPACCEPTED)
    GUICtrlSetLimit(-1, 7)
    GUICtrlCreateLabel ( "Enter the 7 digit file number you are looking for and press Search.", 10, 30)
    GUICtrlCreateLabel ( "NOTE: The Digital Numeric Archive only consists of Auditor File", 10, 50)
    GUICtrlCreateLabel ( "Numbers 2430986 - 3170287.", 10, 66)
    $btn = GUICtrlCreateButton("Search", 130, 5, 60, 20)
    $btn2 = GUICtrlCreateButton("Exit", 130, 90, 60, 20)
    GUICtrlSetOnEvent($btn2, "Close") ; Tells to go to Close function if Exit button is pressed

    GUISetState()
EndFunc

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            $FileNumber = GUICtrlRead($file)
            ExitLoop
    EndSelect
WEnd

If $FileNumber > 3170287 Or $FileNumber < 2430986 Then
    MsgBox(4096, "Number Out of Range", "The number must be between 2430986 and 3170287")
    _Main() ; Goes back to GUI function
Endif
If $FileNumber >= 2430986 And $FileNumber <= 2433260 Then
    ShellExecute ("2430986-2433260.pdf")
Endif

;closes script if exit button is pressed
Func Close()
    Exit
EndFunc

EDIT: Added the "goto" effect

Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

When I run this I get

Line 3

-Main()

^ERROR

Error: Unknown function Name

I coded it this way:

#include <GUIConstants.au3>

_Main() ; starts GUI part

Func Main()

GUICreate("Numerics Search", 320, 120)

$file = GUICtrlCreateInput("", 10, 5, 100, 20, $ES_NUMBER)

GUICtrlSetState(-1, $GUI_NODROPACCEPTED)

GUICtrlSetLimit(-1, 7)

GUICtrlCreateLabel ( "Enter the 7 digit file number you are looking for and press Search.", 10, 30)

GUICtrlCreateLabel ( "NOTE: The Digital Numeric Archive only consists of Auditor File", 10, 50)

GUICtrlCreateLabel ( "Numbers 2430986 - 3170287.", 10, 66)

$btn = GUICtrlCreateButton("Search", 130, 5, 60, 20)

$btn2 = GUICtrlCreateButton("Exit", 130, 90, 60, 20)

GUISetState()

EndFunc

$msg = 0

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

Select

Case $msg = $btn

$FileNumber = GUICtrlRead($file)

ExitLoop

EndSelect

WEnd

If $FileNumber > 3170287 Or $FileNumber < 2430986 Then

MsgBox(4096, "Number Out of Range", "The number must be between 2430986 and 3170287")

_Main() ; Goes back to GUI

Endif

Func Close ()

Exit

EndFunc

There aren't GOTO commands anymore in AutoIt there are ways to get a similar effect though.

For exit button:

#include <GUIConstants.au3>

_Main() ; starts GUI function

;GUI function
Func Main()
    GUICreate("Numerics Search", 320, 120)
    $file = GUICtrlCreateInput("", 10, 5, 100, 20, $ES_NUMBER)
    GUICtrlSetState(-1, $GUI_NODROPACCEPTED)
    GUICtrlSetLimit(-1, 7)
    GUICtrlCreateLabel ( "Enter the 7 digit file number you are looking for and press Search.", 10, 30)
    GUICtrlCreateLabel ( "NOTE: The Digital Numeric Archive only consists of Auditor File", 10, 50)
    GUICtrlCreateLabel ( "Numbers 2430986 - 3170287.", 10, 66)
    $btn = GUICtrlCreateButton("Search", 130, 5, 60, 20)
    $btn2 = GUICtrlCreateButton("Exit", 130, 90, 60, 20)
    GUICtrlSetOnEvent($btn2, "Close") ; Tells to go to Close function if Exit button is pressed

    GUISetState()
EndFunc

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            $FileNumber = GUICtrlRead($file)
            ExitLoop
    EndSelect
WEnd

If $FileNumber > 3170287 Or $FileNumber < 2430986 Then
    MsgBox(4096, "Number Out of Range", "The number must be between 2430986 and 3170287")
    _Main() ; Goes back to GUI function
Endif
If $FileNumber >= 2430986 And $FileNumber <= 2433260 Then
    ShellExecute ("2430986-2433260.pdf")
Endif

;closes script if exit button is pressed
Func Close()
    Exit
EndFunc

EDIT: Added the "goto" effect

Share this post


Link to post
Share on other sites

_Main() ; starts GUI part

Func Main()

Looks like a problem to me... you are calling a function called _Main and the function name is Main

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

_Main() ; starts GUI part

Func Main()

Looks like a problem to me... you are calling a function called _Main and the function name is Main

Dale

Yeah typo XP

Sorry about that, gotta make sure my function titles match up.


[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

Yeah typo XP

Sorry about that, gotta make sure my function titles match up.

OK, I changed everything to just Main, also had to move the EndFunc for main all the way to the end of my If statements, otherwise I got an error message saying my $btn variable had not been declared. So now if user types in a out of range number they are taken to the beginning of the Main. Cool. However, my Exit button is still not working. Doesn't there need to be some kind of if statement like If $bt2 = 1 then Func Close ()?

#include <GUIConstants.au3>

Main() ; starts GUI part

Func Main()

GUICreate("Numerics Search", 320, 120)

$file = GUICtrlCreateInput("", 10, 5, 100, 20, $ES_NUMBER)

GUICtrlSetState(-1, $GUI_NODROPACCEPTED)

GUICtrlSetLimit(-1, 7)

GUICtrlCreateLabel ( "Enter the 7 digit file number you are looking for and press Search.", 10, 30)

GUICtrlCreateLabel ( "NOTE: The Digital Numeric Archive only consists of Auditor File", 10, 50)

GUICtrlCreateLabel ( "Numbers 2430986 - 3170287.", 10, 66)

$btn = GUICtrlCreateButton("Search", 130, 5, 60, 20)

$btn2 = GUICtrlCreateButton("Exit", 130, 90, 60, 20)

GUISetState()

$msg = 0

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

Select

Case $msg = $btn

$FileNumber = GUICtrlRead($file)

ExitLoop

EndSelect

WEnd

If $FileNumber > 3170287 Or $FileNumber < 2430986 Then

MsgBox(4096, "Number Out of Range", "The number must be between 2430986 and 3170287")

Main() ; Goes back to GUI

Endif

if $FileNumber >= 2430986 And $FileNumber <= 2433260 Then

ShellExecute ("2430986-2433260.pdf")

Endif

EndFunc

Func Close()

Exit

EndFunc

Share this post


Link to post
Share on other sites

I Lol'd.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>

Func _Main()
    GUICreate("Numerics Search", 320, 120)
    $file = GUICtrlCreateInput("", 10, 5, 100, 20, $ES_NUMBER)
    GUICtrlSetState(-1, $GUI_NODROPACCEPTED)
    GUICtrlSetLimit(-1, 7)
    GUICtrlCreateLabel ( "Enter the 7 digit file number you are looking for and press Search.", 10, 30)
    GUICtrlCreateLabel ( "NOTE: The Digital Numeric Archive only consists of Auditor File", 10, 50)
    GUICtrlCreateLabel ( "Numbers 2430986 - 3170287.", 10, 66)
    $btn = GUICtrlCreateButton("Search", 130, 5, 60, 20)
    $btn2 = GUICtrlCreateButton("Exit", 130, 90, 60, 20)
    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $btn2
                Exit
            Case $msg = $btn
                $num = Int(GUICtrlRead($file))
                GUIDelete()
                Return $num
        EndSelect
    WEnd
EndFunc

While 1
    $FileNumber = _Main()
    If $FileNumber >= 2430986 And $FileNumber <= 3170287 Then 
        MsgBox(64, "OK", "Number is OK")
;~      ShellExecute ("2430986-2433260.pdf")
        Exit
    EndIf
    MsgBox(4096, "Number Out of Range", "The number must be between 2430986 and 3170287")
WEnd

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

#include <GUIConstants.au3>

Func _Main()
    GUICreate("Numerics Search", 320, 120)
    $file = GUICtrlCreateInput("", 10, 5, 100, 20, $ES_NUMBER)
    GUICtrlSetState(-1, $GUI_NODROPACCEPTED)
    GUICtrlSetLimit(-1, 7)
    GUICtrlCreateLabel ( "Enter the 7 digit file number you are looking for and press Search.", 10, 30)
    GUICtrlCreateLabel ( "NOTE: The Digital Numeric Archive only consists of Auditor File", 10, 50)
    GUICtrlCreateLabel ( "Numbers 2430986 - 3170287.", 10, 66)
    $btn = GUICtrlCreateButton("Search", 130, 5, 60, 20)
    $btn2 = GUICtrlCreateButton("Exit", 130, 90, 60, 20)
    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $btn2
                Exit
            Case $msg = $btn
                $num = Int(GUICtrlRead($file))
                GUIDelete()
                Return $num
        EndSelect
    WEnd
EndFunc

While 1
    $FileNumber = _Main()
    If $FileNumber >= 2430986 And $FileNumber <= 3170287 Then 
        MsgBox(64, "OK", "Number is OK")
;~      ShellExecute ("2430986-2433260.pdf")
        Exit
    EndIf
    MsgBox(4096, "Number Out of Range", "The number must be between 2430986 and 3170287")
WEnd
Thanks for the help Zenda, Bala, and Dale. All works well. Edited by williamk

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