vorwärts rückwärts mit array

  • Hallo an alle,

    ich bin grade dabei wieder ein wenig zu üben und hätte da auch gleich wieder eine Frage :)

    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 625, 443, 192, 124)
    $zuruck = GUICtrlCreateButton("<---------", 24, 88, 225, 57, $WS_GROUP)
    $vor = GUICtrlCreateButton("--------->", 368, 88, 217, 57, $WS_GROUP)
    $Label1 = GUICtrlCreateLabel("Label1", 192, 264, 266, 33)
    GUICtrlSetFont(-1, 18, 800, 0, "Arial Narrow")
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetBkColor(-1, 0x000000)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    #include <Array.au3>
    Local $avArray[10]

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

    $avArray[0] = "JPM"
    $avArray[1] = "Holger"
    $avArray[2] = "Jon"
    $avArray[3] = "Larry"
    $avArray[4] = "Jeremy"
    $avArray[5] = "Valik"
    $avArray[6] = "Cyberslug"
    $avArray[7] = "Nutster"
    $avArray[8] = "JdeB"
    $avArray[9] = "Tylo"

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    case $zuruck

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

    Case $vor

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

    EndSwitch
    WEnd

    [/autoit]

    Ich will das wenn ich vorwärts drücke das er mir nach der reihe die Namen in den Label einträgt. Wie so ein vorwärts rückwärts Knopf an der Fernbedienung. Ich habe schon einiges versucht jedoch bin ich immer wieder gescheitert :(

    Kann mir da vllt. einer weiter helfen ?

  • Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 625, 443, 192, 124)
    $zuruck = GUICtrlCreateButton("<---------", 24, 88, 225, 57, $WS_GROUP)
    $vor = GUICtrlCreateButton("--------->", 368, 88, 217, 57, $WS_GROUP)
    $Label = GUICtrlCreateLabel("", 192, 264, 266, 33)
    GUICtrlSetFont(-1, 18, 800, 0, "Arial Narrow")
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetBkColor(-1, 0x000000)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    #include <Array.au3>
    Local $avArray[10] = ["JPM","Holger","Jon","Larry","Jeremy","Valik","Cyberslug","Nutster","JdeB","Tylo"]
    GUICtrlSetData($Label, $avArray[0])
    $iActive = 0

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

    While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $zuruck
    $iActive -= 1
    If $iActive < 0 Then $iActive = UBound($avArray) - 1
    GUICtrlSetData($Label, $avArray[$iActive])
    Case $vor
    $iActive += 1
    If $iActive >= UBound($avArray) Then $iActive = 0
    GUICtrlSetData($Label, $avArray[$iActive])
    EndSwitch
    WEnd

    [/autoit]
  • Eine Frage hätte ich noch, wie kann ich eine Funktion noch mit einfügen ? Sprich wenn John im Laben erscheint soll er mir ne msgbox ausgeben...

  • Spoiler anzeigen
    [autoit]

    While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $zuruck
    $iActive -= 1
    If $iActive < 0 Then $iActive = UBound($avArray) - 1
    GUICtrlSetData($Label, $avArray[$iActive])
    If $avArray[$iActive] = "Jon" Then MsgBox(262144, "Jon", "Ich bin Jon")
    Case $vor
    $iActive += 1
    If $iActive >= UBound($avArray) Then $iActive = 0
    GUICtrlSetData($Label, $avArray[$iActive])
    If $avArray[$iActive] = "Jon" Then MsgBox(262144, "Jon", "Ich bin Jon")
    EndSwitch
    WEnd

    [/autoit]
  • [autoit]

    While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $zuruck
    $iActive -= 1
    If $iActive < 0 Then $iActive = UBound($avArray) - 1
    GUICtrlSetData($Label, $avArray[$iActive])
    If $avArray = "Jon" Then MsgBox(262144, "Jon", "Ich bin Jon")
    Case $vor
    $iActive += 1
    If $iActive >= UBound($avArray) Then $iActive = 0
    GUICtrlSetData($Label, $avArray[$iActive])
    If $avArray = "Jon" Then MsgBox(262144, "Jon", "Ich bin Jon")
    EndSwitch
    WEnd

    [/autoit]

    ich habe es so geschrieben und das hat nicht geklappt.... wieso nmuss denn das [$iActive] drinne stehen ??

  • Ein Array ist keine normale Variable. Du musst schon angeben welchen genauen Wert du im Array haben willst.

    Edit:
    Hier mal eine bessere Version mit mehr Übersicht.

    Spoiler anzeigen
    [autoit]

    While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $zuruck, $vor
    Local $Name
    If $nMsg = $zuruck Then $Name = _GetActiveUser($avArray, GUICtrlRead($Label), -1)
    If $nMsg = $vor Then $Name = _GetActiveUser($avArray, GUICtrlRead($Label), 1)
    GUICtrlSetData($Label, $Name)

    If $Name = "Jon" Then MsgBox(0, "", "Jon")
    EndSwitch
    WEnd

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

    Func _GetActiveUser($aArray, $sLabel, $iMove)
    If $aArray[0] = $sLabel And $iMove = -1 Then Return $aArray[UBound($aArray) - 1]
    If $aArray[UBound($aArray) - 1] = $sLabel And $iMove = 1 Then Return $aArray[0]
    For $i = 0 To UBound($aArray) - 1
    If $aArray[$i] = $sLabel Then Return $aArray[$i + $iMove]
    Next
    EndFunc ;==>_GetActiveUser

    [/autoit]