Loop stoppen

  • und wiedermal weiss ich nicht weiter und benötige Hilfe :/. Ich habe in meinem Script ein Loop, der bei jedem Durchgang prüfen soll, ob man auf den Stop Button geklickt hat, oder nicht. Dies hab ich über eine Variable ($stop) gemacht. Leider funktioniert das ganze irgentwie nicht :S.

    [autoit]

    #include <IE.au3>
    #include <GUIConstants.au3>
    #include <INet.au3>
    #include <string.au3>
    #include <array.au3>
    #include <file.au3>

    [/autoit][autoit][/autoit][autoit]

    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x00FF00)

    [/autoit][autoit][/autoit][autoit]

    $Form1 = GUICreate("Test", 755, 155, 192, 125, $DS_MODALFRAME, $WS_EX_TOOLWINDOW)
    $Button_start = GUICtrlCreateButton("Start", 87, 0, 86, 17)
    $Button_stop = GUICtrlCreateButton("Stop", 173, 0, 86, 17)
    $Input_hotel = GUICtrlCreateInput("Hotel", 1, 16, 160, 17, -1, $WS_EX_CLIENTEDGE)
    $Input_habbo = GUICtrlCreateInput("Habboname", 1, 32, 160, 17, -1, $WS_EX_CLIENTEDGE)
    $Input_amount = GUICtrlCreateInput("Amount", 1, 48, 160, 17, -1, $WS_EX_CLIENTEDGE)
    $Input_delay = GUICtrlCreateInput("Delay", 1, 64, 160, 17, -1, $WS_EX_CLIENTEDGE)
    $Input_id = GUICtrlCreateInput("Habbo ID", 1, 80, 160, 17, -1, $WS_EX_CLIENTEDGE)
    $Input_message = GUICtrlCreateInput("Message", 1, 96, 160, 17, -1, $WS_EX_CLIENTEDGE)
    $Input_status = GUICtrlCreateInput("Status - Inactive - Press Load Habbo to Start", 1, 113, 747, 17, $ES_READONLY, $WS_EX_CLIENTEDGE)

    [/autoit][autoit][/autoit][autoit]

    GUISetState(@SW_SHOW)

    [/autoit][autoit][/autoit][autoit]

    Global $stop = 0

    [/autoit][autoit][/autoit][autoit]

    While 1

    $msg = GuiGetMsg()

    Select

    [/autoit][autoit][/autoit][autoit]

    Case $msg = $Button_start
    $oIE = _IECreate ("https://www." & GUICtrlREad($Input_hotel) & "/account/login")
    $while = 0
    $status = 0
    While $while < GUICtrlREad($Input_amount)
    stop()
    WEnd

    Case $msg = $Button_stop
    $stop = 1

    Case Else
    ;;;;;;;
    EndSelect

    WEnd

    [/autoit][autoit][/autoit][autoit]

    Func stop()
    If $stop = 1 Then
    $while = GUICtrlREad($Input_amount)
    ElseIf $stop = 0 Then
    _IENavigate ($oIE, "http://" & GUICtrlREad($Input_hotel) & "/myhabbo/guestbook/add?ownerId=" & GUICtrlRead($Input_id) & "&message=" & GUICtrlRead($Input_message) & "&_=")
    $status = $status + 1
    Sleep(GUICtrlREad($Input_delay))
    $while = $while + 1
    EndIf
    EndFunc

    [/autoit]

    Ich hab noch gesehen dass man bei der "ExitLoop [level]" Funktion das level, also welchen Loop man beenden will einstellen kann. Nur muss man dazu ja irgentwo bei "While" noch ein level eingeben können, oder wie is das gemeint?

    3 Mal editiert, zuletzt von Deadman (23. Dezember 2006 um 17:50)

  • joa des wär ne möglichkeit...hier mal zusammengebastelt..

    [autoit]

    while 1
    ;do sthg
    If $stop Then
    ExitLoop
    EndIF
    WEnd

    [/autoit]


    man könnte des ganze auch iner vorprüfender schleife oder nachprüfenden schleife machen...
    vorprüfend:

    [autoit]

    While !$stop
    ;do stgh
    WEnd

    [/autoit]


    oder nachprüfend

    [autoit]

    Do
    ;do stgh
    Until $stop

    [/autoit]


    Vorteil einer nachprüfenden schleife...programmabschnitt wird in jedem falle einmal durchlaufen(kann aber auch der nachteil dabei sein)
    $stop drückt bei allen besipielen aus ob der button gedrückt wurde oder nicht....

  • Mein Problem ist, wie kann ich einen Loop über eine Funktion beenden.

    [autoit]

    #include <IE.au3>
    #include <GUIConstants.au3>
    #include <INet.au3>
    #include <string.au3>
    #include <array.au3>
    #include <file.au3>

    [/autoit][autoit][/autoit][autoit]

    $Form1 = GUICreate("Test", 755, 155, 192, 125, $DS_MODALFRAME, $WS_EX_TOOLWINDOW)
    $Button_start = GUICtrlCreateButton("Start", 87, 0, 86, 17)
    $Button_stop = GUICtrlCreateButton("Stop", 173, 0, 86, 17)
    $Input_amount = GUICtrlCreateInput("Amount", 1, 48, 160, 17, -1, $WS_EX_CLIENTEDGE)
    $Input_status = GUICtrlCreateInput("Status - Inactive - Press Start to start", 1, 113, 747, 17, $ES_READONLY, $WS_EX_CLIENTEDGE)

    [/autoit][autoit][/autoit][autoit]

    Global $stop = 0
    Global $oIE = _IECreate ("http://www.habbo.ch")

    [/autoit][autoit][/autoit][autoit]

    GUISetState(@SW_SHOW)

    [/autoit][autoit][/autoit][autoit]

    While 1

    Opt("GUIOnEventMode", 1)
    GUICtrlSetOnEvent($Button_stop, "stop")
    GUICtrlSetOnEvent($Button_start, "start")

    WEnd

    [/autoit][autoit][/autoit][autoit]

    Func stop()
    Opt("GUIOnEventMode", 1)
    GUICtrlSetOnEvent($Button_stop, "stop")
    GUICtrlSetOnEvent($Button_start, "start")
    $stop = 1
    GUICtrlSetData($Input_status, "Status - Inactive - Press Start to start")
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func start()
    Opt("GUIOnEventMode", 1)
    GUICtrlSetOnEvent($Button_stop, "stop")
    GUICtrlSetOnEvent($Button_start, "start")
    $while = 0
    $status = 0
    $stop = 0
    While $while < GUICtrlREad($Input_amount)
    If $stop = 1 Then
    ExitLoop
    ElseIf $stop = 0 Then
    _IENavigate ($oIE, "http://www.habbo.ch")
    $status = $status + 1
    GUICtrlSetData($Input_status, "Status - Active - Page Reloading... - " & $status & " Reloads")
    $while = $while + 1
    Sleep(3000)
    EndIf
    WEnd
    EndFunc

    [/autoit]

    Das einzige was nicht funktioniert ist:

    [autoit]

    If $stop = 1 Then
    ExitLoop

    [/autoit]

    Währen der Schleife von der Funktion start(), passiert wenn man auf den Stop-Button klickt nichts.

    2 Mal editiert, zuletzt von Deadman (24. Dezember 2006 um 14:38)

    • Offizieller Beitrag
    [autoit]

    While $while < GUICtrlREad($Input_amount)
    If $stop = 1 Then
    ExitLoop

    [/autoit]

    Das "ExitLoop" ist natürlich wirkungslos, weil du damit nur die Schleife: "While $while < GUICtrlREad($Input_amount)" verlässt.
    Wie mausilein schon richtig sagte, solltest du an dieser Stelle einfügen:

    [autoit]

    While $while < GUICtrlREad($Input_amount)
    If $stop = 1 Then
    Return $returnvariable ;

    [/autoit]


    Diese $returnvariable kannst du dann auswerten, oder du gibst nur "Return" um die Funktion zu verlassen.

    EDIT

    So, ich habs mal "entschlackt" und angepasst. Hoffe, das ist was du wolltest.
    Und Happy Xmas!

    Spoiler anzeigen
    [autoit]

    #include <IE.au3>
    #include <GUIConstants.au3>
    #include <INet.au3>
    #include <string.au3>
    #include <array.au3>
    #include <file.au3>
    Opt("GUIOnEventMode", 1)
    Global $stop = 0
    Global $oIE = _IECreate ("http://www.habbo.ch")

    [/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("Test", 755, 155, 192, 125, $DS_MODALFRAME, $WS_EX_TOOLWINDOW)
    $Button_start = GUICtrlCreateButton("Start", 87, 0, 86, 17)
    GUICtrlSetOnEvent(-1, "start")
    $Button_stop = GUICtrlCreateButton("Stop", 173, 0, 86, 17)
    GUICtrlSetOnEvent(-1, "stop")
    $Input_amount = GUICtrlCreateInput("Amount", 1, 48, 160, 17, -1, $WS_EX_CLIENTEDGE)
    $Input_status = GUICtrlCreateInput("Status - Inactive - Press Start to start", 1, 113, 747, 17, $ES_READONLY, $WS_EX_CLIENTEDGE)
    GUISetState(@SW_SHOW)

    Do
    Sleep(100)
    Until $stop = 1

    Func stop()
    $stop = 1
    GUICtrlSetData($Input_status, "Status - Inactive - Press Start to start")
    EndFunc

    Func start()
    $while = 0
    $status = 0
    $stop = 0
    While $while < GUICtrlREad($Input_amount)
    If $stop = 1 Then
    Return
    ElseIf $stop = 0 Then
    _IENavigate ($oIE, "http://www.habbo.ch")
    $status = $status + 1
    GUICtrlSetData($Input_status, "Status - Active - Page Reloading... - " & $status & " Reloads")
    $while = $while + 1
    Sleep(3000)
    EndIf
    WEnd
    EndFunc

    [/autoit]