cloq Posted February 16, 2010 Share Posted February 16, 2010 Hello,I am quite the newbie with arrays and stringsplits. I have copied and played with random bits of code from various authors and scripters here on this forum (Thank you!).I am trying out a script that reads titles from a csv file (book.csv), populates a combobox with titles, and when a title is selected (by choosing and clicking ok) the user will get basic info about publisher name, title, and pages. I am trying to put a variable to (one for each), publisher, title and pages. So when the user clicks ok, based on the title picked, msgbox = var1 + var2 + var3.Any help would be appreciated. Here is my current progress:Pub, Title, Pages Harper, Title01, 111 Coby, Title02, 222 Tor, Title03, 333 Random, Title04, 444expandcollapse popup#include <GUIConstants.au3> #include <File.au3> Global $in_filename $in_filename = "book.csv" Dim $lines,$Display, $NumCols _FileReadToArray($in_filename, $lines) $Columns = StringSplit($lines[1], ",") $NumCols=$Columns[1] Dim $array[ $lines[0] ][ $Columns[0] ] For $i = 1 To $lines[0] $Columns = StringSplit($lines[$i], ",") If $Columns[0] = 1 Then Continueloop For $j = 1 To $Columns[0] $array[$i-1][$j-1] = $Columns[$j] Next Next $Rows=$Lines[0]-1 Global $ColumnA, $AllColumnA $M = 1 While $M <= $Rows -1 $ColumnA=$Array[$m][1] & "|" $M = $M + 1 $AllColumnA=$AllColumnA & $ColumnA Wend _Content() Func _Content() Global $menu1, $n1, $n2, $msg, $menustate, $menutext Global $Brand GUICreate("Test",400,200,-1,-1) $n1 = GUICtrlCreateCombo("", 10,10,100) GUICtrlSetData(-1,$AllColumnA) $n2 = GUICtrlCreateButton("Read", 10, 110, 50) GUICtrlSetState(-1, $GUI_FOCUS) GUISetState () Do $msg = GUIGetMsg() Select Case $msg = $n2 $Brand = GUICtrlRead($n1) MsgBox(0, "BookInfo", $Brand) EndSelect Until $msg = $GUI_EVENT_CLOSE Exit EndFunc Link to comment Share on other sites More sharing options...
enaiman Posted February 16, 2010 Share Posted February 16, 2010 I kept a little bit of your code - here is the working result: expandcollapse popup#include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> Global $in_filename $in_filename = "book.csv" Dim $lines,$Display, $ComboText = "" _FileReadToArray($in_filename, $lines) $Columns = StringSplit($lines[1], ",") Dim $MemARRAY [$lines[0]+1][$Columns[0]+1] For $i = 1 To $lines[0] ;$MemARRAY [1][1] = "Pub", $MemARRAY [1][2] = "Title", $MemARRAY [1][3] = "Pages" $Columns = StringSplit($lines[$i], ",") If $i <> 1 Then $ComboText &= $Columns[1]&"|" ;prepare the string to fill the combo (skip the header) For $j = 1 To $Columns[0] $MemARRAY [$i][$j] = StringStripWS($Columns[$j], 3) Next Next Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 217, 151, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $Combo1 = GUICtrlCreateCombo("", 8, 24, 201, 25) GUICtrlSetData(-1, $ComboText, "") GUICtrlSetOnEvent(-1, "Combo1Change") $Label1 = GUICtrlCreateLabel("", 8, 56, 196, 81, $WS_BORDER) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func Combo1Change() If GUICtrlRead($Combo1) <> "" Then GUICtrlSetData($Label1, "") MsgBox(0, "", GUICtrlRead($Combo1)) Local $idx = _ArraySearch($MemARRAY, GUICtrlRead($Combo1), 0, 0, 0, 0, 1, 1) If @error Then MsgBox(16, "Error", "Can't find value") Exit EndIf Local $FinalMessage = $MemARRAY[1][1]&": "&$MemARRAY [$idx][1]&@CRLF & _ $MemARRAY[1][2]&": "&$MemARRAY [$idx][2]&@CRLF & _ $MemARRAY[1][3]&": "&$MemARRAY [$idx][3]&@CRLF GUICtrlSetData($Label1, $FinalMessage) Else Return EndIf EndFunc Func Form1Close() Exit EndFunc It is up to you to adapt this example to suit your code - I've noticed you have used #include <GUIConstants.au3> - maybe it is time for you to upgrade your AutoIt to at least 3.3 ? SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
cloq Posted February 16, 2010 Author Share Posted February 16, 2010 It is up to you to adapt this example to suit your code - I've noticed you have used #include <GUIConstants.au3> - maybe it is time for you to upgrade your AutoIt to at least 3.3 ?Awesome! This seems to be what I was trying to accomplish without the know how (ended up with a headache instead but learned a few other things in the process). Just upgraded my Autoit too. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now