Button mit 2 Funktionen

  • Hey Leute,

    ich habe einen Button der 2 Funktionen enthalten soll. aber nicht einfach so hintereinander 2 Funktionen Durchführen, sondern ein klick erste Funktion wird durchgeführt und der nächste Click führt die 2. Funktion durch das soll aber auch nicht einfach so hintereinander laufen. Ich will dass der Button solange die 1. Funktion durchführt, bis z.B. das Passwort richtig eingegeben wurde erst dann soll die 2 Funktion des Buttons ausgeführt werden können!

    Ich hoffe ihr könnt mit meiner Erklärung etwas anfangen und könnt mir helfen....

    LG
    Ququknife

    Frühere Werke: PC-Nutzungslaufzeit

    3 Mal editiert, zuletzt von Ququknife (16. November 2012 um 22:11) aus folgendem Grund: Präfix Änderung

  • Dann setzt du einfach eine Variable auf 1 wenn das Passwort stimmt und bei jedem klick auf den Button fragst du diese Variable ab. Je nach dem ob sie 1 ist oder nicht führst du dann die entsprechende Funktion aus.

    Gruss Shadowigor

  • If Abfrage die Funktion 2 ausführt wenn das Passwort richtig war, ansonsten Funktion 1.

    Andy hat mir ein Schnitzel gebacken aber da war ein Raupi drauf und bevor Oscar das Bugfixen konnte kam Alina und gab mir ein AspirinJunkie.

  • Es ist doch noch nicht ganz gelöst.

    noch eine Frage, kann ich dem selben Button, nachdem der schon die Passwortabfrage gemacht hat nochmal 2 Funktionen zuweisen?
    Also er soll nachwievor die Passwortabfrage durchführen wenn das passwort falsch ist sollen keine Weiteren Funktionen rein aber wenn das Passwort richtig ist, würde ich dem Button gerne noch 2 verschiedene Funktionen zuweißen, geht das? wenn ja wie mache ich das??

  • einfach immer so weiter?

    [autoit]


    if(pw==true)
    if(funktion1==true)
    if(funktion2==true)
    else mach dies
    else mach das
    else frag pw

    [/autoit]
  • Mit einer einfache If Abfrage kann ich ja den Button drauf Programmieren dass er ir das Passwort ausließt und bestimmt ob richtig oder falsch wenn aber dan das passwort stimmt soll der button eine weitere aktion ausführen können ist das machbar??

  • Hier mal ein Beispiel:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>

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

    Opt('GUIOnEventMode', 1)
    Opt('GUICloseOnEsc', 0)

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

    Global $iButtonModus = 1

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

    Global Const $hGUI = GUICreate('Beispiel', 120, 70)
    Global Const $iInput = GUICtrlCreateInput('AutoIt', 10, 10, 100, 20)
    Global Const $iButton = GUICtrlCreateButton('Button Funktion 1', 10, 40, 100, 20)
    GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $hGUI)
    GUICtrlSetOnEvent($iButton, '_Button')
    GUISetState(@SW_SHOW, $hGUI)

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

    While Sleep(1000)
    WEnd

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

    Func _Exit()
    Exit
    EndFunc

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

    Func _Button()
    Switch $iButtonModus
    Case 1
    If GUICtrlRead($iInput) == 'AutoIt' Then
    $iButtonModus = 2
    GUICtrlSetState($iInput, $GUI_HIDE)
    GUICtrlSetData($iInput, '')
    GUICtrlSetData($iButton, 'Button Funktion 2')
    ControlMove($hGUI, '', $iButton, 10, 10, 100, 50)
    EndIf
    Case 2
    $iButtonModus = 3
    MsgBox(0, 'Nachricht:', 'Sie haben zum zweiten mal auf den selber Button geklickt!')
    GUICtrlSetData($iInput, 'Eingabe')
    GUICtrlSetData($iButton, 'Button Funktion 3')
    ControlMove($hGUI, '', $iButton, 10, 10, 100, 20)
    ControlMove($hGUI, '', $iInput, 10, 40, 100, 20)
    GUICtrlSetState($iInput, $GUI_SHOW)
    Case 3
    $iButtonModus = 4
    GUICtrlSetData($iButton, 'Button Funktion 4')
    MsgBox(0, 'Ausgabe:', GUICtrlRead($iInput))
    GUICtrlSetData($iInput, 'Programm beenden!')
    Case 4
    _Exit()
    EndSwitch
    EndFunc

    [/autoit]
  • Ach so ist das gemeint. ^^
    Hier noch ein Beispiel mit OnEventMode und einer, für diese Situation besser geeigneten, statischen Variable:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>

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

    Opt("GUIOnEventMode", 1)

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

    $hWnd = GUICreate("Example", 200, 50)
    $cButton = GUICtrlCreateButton("Enter Pass", 60, 12, 80, 25)
    GUISetState()

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

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUICtrlSetOnEvent($cButton, "_Button")

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

    While Sleep(1000)
    WEnd

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

    Func _Button()
    Local Static $iMode = 0
    If $iMode > 3 Then $iMode = 0
    Switch $iMode
    Case 0
    $sPass = InputBox("Password", "Pass:", "Pass")
    If Not $sPass == "Pass" Then Return
    GUICtrlSetData($cButton, "Function 1")
    Case 1
    MsgBox(64, "Mode: " & $iMode, "Switching to next mode.")
    GUICtrlSetData($cButton, "Function 2")
    Case 2
    MsgBox(64, "Mode: " & $iMode, "Switching to next mode.")
    GUICtrlSetData($cButton, "Function 3")
    Case 3
    MsgBox(64, "Mode: " & $iMode, "Switching to next mode.")
    GUICtrlSetData($cButton, "Enter Pass")
    EndSwitch
    $iMode += 1
    EndFunc

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

    Func _Exit()
    Exit
    EndFunc

    [/autoit]
  • Hier eine Lösung mit Array. ;)

    Spoiler anzeigen
    [autoit]


    #AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 5 -w 6
    ;~ #include <GUIConstants.au3> ;i -3 = $GUI_EVENT_CLOSE

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

    Opt("GUIOnEventMode", 1)

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

    Global $etfunc[4] = ["Function 1", "Function 2", "Function 3", "Enter Pass"]

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

    $hWnd = GUICreate("Example", 200, 50)
    GUISetOnEvent(-3, "_Exit") ;i -3 = $GUI_EVENT_CLOSE
    $cButton = GUICtrlCreateButton("Enter Pass", 60, 12, 80, 25)
    GUICtrlSetOnEvent($cButton, "_Button")

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

    GUISetState()

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

    While Sleep(1000)
    WEnd

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

    Func _Button()
    Local Static $iMode = 0
    If $iMode > 3 Then $iMode = 0
    Switch $iMode
    Case 0
    $sPass = InputBox("Password", "Pass:", "Pass")
    If $sPass <> "Pass" Then Return
    ;~ Hier Deine Function 1
    Case 1
    ;~ Hier Deine Function 2
    Case 2
    ;~ Hier Deine Function 3
    Case 3
    ;~ Hier Deine Function Enter Pass
    EndSwitch

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

    MsgBox(64, "Mode: " & $iMode + 1, "Switching to next mode.")
    GUICtrlSetData($cButton, $etfunc[$iMode])

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

    $iMode += 1
    EndFunc ;==>_Button

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

    Func _Exit()
    Exit
    EndFunc ;==>_Exit
    ; Ende

    [/autoit]