Array ausgeben

02/23/2012 22:21 maxi39#1
Hey,

ich hab grad irwi ne denkblockade also:

PHP Code:
Global  $player[8][2] = [["player 1"0], ["player 2",4], ["player 3",8], ["player 4"12], ["player 5"16] , ["player 6"20], ["player 7"24], ["player 8"28]]

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 GUICreate("speed"69886192124)

$combo GUICtrlCreateCombo("Player"81614525BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$COMBO1 GUICtrlSetData(-1"" $PLAYER[0][0] & "|" $PLAYER[1][0] & "|" $PLAYER[2][0] & "|" $PLAYER[3][0] & "|" $PLAYER[4][0] & "|" $PLAYER[5][0] & "|" $PLAYER[6][0] & "|" $PLAYER[7][0] & "")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


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

    EndSwitch

MsgBox(0,"",GUICtrlRead($COMBO))


WEnd 
[/PHP]


so bekomme ich nur beim auslesen was da in der comboboy auch steht, ich möchte aba wenn zum beispiel player 5 ausgewählt wird, das in der msg box statt player 5 steht, nur 16 also das $player[4][1] ausgegeben wird statt $player[4][0] ich hab aba irwi grad kein plan wie xD
02/24/2012 00:02 KDeluxe#2
Wenn die Zahl am Ende des Textes in gleichmäßigen Abständen zunimmt wäre das z. B. eine einfache Lösung:
Code:
#include <ComboConstants.au3>

Dim  $Array[4][2] = [["Bla 1", 123], ["Bla 2", 456], ["Bla 3", 789], ["Bla 4", 0]]

GUICreate("Blaa", 150, 100)
$DropDownList = GUICtrlCreateCombo($Array[0][0], 5, 5, 140, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
For $i = 0 To UBound($Array) - 1
	GUICtrlSetData($DropDownList, $Array[$i][0], True)
Next
$Button = GUICtrlCreateButton("MessageBox", 5, 35, 140, 25)
GUISetState()


Do
	$Msg = GUIGetMsg()
	If $Msg == $Button Then
		MsgBox(0, "", $Array[StringRight(GUICtrlRead($DropDownList), 1) - 1][1])
	EndIf

	Sleep(25)
Until $Msg == -3
Andernfalls könntest du das Array mit einer For-Schleife durchgehen und die Texte vergleichen, sobald der Text übereinstimmt gibst du die Zahl des des Array aus.
Code:
#include <ComboConstants.au3>

Dim  $Array[4][2] = [["Bla 1", 123], ["Bla 2", 456], ["Bla 3", 789], ["Bla 4", 0]]

GUICreate("Blaa", 150, 100)
$DropDownList = GUICtrlCreateCombo($Array[0][0], 5, 5, 140, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
For $i = 0 To UBound($Array) - 1
	GUICtrlSetData($DropDownList, $Array[$i][0], True)
Next
$Button = GUICtrlCreateButton("MessageBox", 5, 35, 140, 25)
GUISetState()


Do
	$Msg = GUIGetMsg()
	If $Msg == $Button Then
		For $i = 0 To UBound($Array) - 1
			If GUICtrlRead($DropDownList) == $Array[$i][0] Then
				MsgBox(0, "", $Array[$i][1])
				ExitLoop
			EndIf
		Next
	EndIf

	Sleep(25)
Until $Msg == -3
02/24/2012 11:58 maxi39#3
danke, aba ich hab mir das dann ganz einfach gemacht :D
Code:
 $comboa = StringSplit(GUICtrlRead($combo)," ")
msgbox(0,"",$comboa[2])
02/24/2012 17:40 KDeluxe#4
Dann würdest du aber nur die Zahl aus dem String erhalten. Von diesem Wert müsstest du noch 1 subtrahieren und dann das $Array[x][1] ausgeben.

Sprich:
Code:
$comboa = StringSplit(GUICtrlRead($combo)," ")
msgbox(0,"", $Array[$comboa[2] - 1][1])
Das macht aber nichts anderes als der erste Code von mir.