Queener Posted February 16, 2015 Share Posted February 16, 2015 I was able to pull data from my ini file to the combobox, but now I'm stuck on how to tell if which item is selected. [ini file] [Justin] User:JThon [James] User:JTim [John] User:JLee So my goal is if combobox item selected John then msgbox "User name is JLee". I know the message part, but what I don't know is how to tell if John is being selected in the combo. If combox is a bad example for this project; do give me a better way of manipulate this project. my code is expandcollapse popup#include-once ; -- Created with ISN Form Studio 2 for ISN AutoIt Studio -- ; #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> #include <GUIListview.au3> #include <GUIListBox.au3> HotKeySet("{ESC}", "_Exit") ;Will need to create to read it from external file $TVID = GUICreate("TVID",331,374,-1,-1,-1,-1) $nameinput = GUICtrlCreateInput("Search By Name",20,20,185,30,-1,512) GUICtrlSetFont(-1,12,400,0,"MS Sans Serif") $bsearch = GUICtrlCreateButton("Search",210,20,100,30,-1,-1) GUICtrlSetFont(-1,12,400,0,"MS Sans Serif") $namelist = GUICtrlCreateCombo("",20,60,290,149,-1,512) $bconnect = GUICtrlCreateButton("Connect To PC",20,255,290,30,-1,-1) GUICtrlSetFont(-1,12,400,0,"MS Sans Serif") $pwdinput = GUICtrlCreateInput("Input Password if different from default",20,220,290,28,-1,512) GUICtrlSetFont(-1,12,400,0,"MS Sans Serif") $bexit = GUICtrlCreateButton("E X I T",110,301,100,57,-1,-1) GUISetState(@SW_SHOW) ;Get Items from files $file = @ScriptDir & "\IDs\TVid.ini" Dim $newvalue, $userlist, $IDs, $userlist[10], $IDs[10] $sections = IniReadSectionNames($file) If @error Then MsgBox(4096, "", "Error occured, probably no INI file.") Else For $i = 1 To $sections[0] $newvalue = $newvalue & $sections[$i] & "|" Next GUICtrlSetData($namelist, StringTrimRight($newvalue, 1)) EndIf while 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Exit() Case $bexit _Exit() case $bconnect Connection() case $bsearch EndSwitch WEnd Func Searcher() ;This is where I need it to find rather which item in the list is selected and then display its user name. Exit ;Erase or comment upon finished code EndFunc Func Connection() Exit ;Erase or comment upon finished code EndFunc Func _Exit() Exit EndFunc Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.") Link to comment Share on other sites More sharing options...
Geir1983 Posted February 16, 2015 Share Posted February 16, 2015 This what you want? expandcollapse popup#include-once ; -- Created with ISN Form Studio 2 for ISN AutoIt Studio -- ; #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> #include <GUIListview.au3> #include <GUIListBox.au3> HotKeySet("{ESC}", "_Exit") ;Will need to create to read it from external file $TVID = GUICreate("TVID",331,374,-1,-1,-1,-1) $nameinput = GUICtrlCreateInput("Search By Name",20,20,185,30,-1,512) GUICtrlSetFont(-1,12,400,0,"MS Sans Serif") $bsearch = GUICtrlCreateButton("Search",210,20,100,30,-1,-1) GUICtrlSetFont(-1,12,400,0,"MS Sans Serif") $namelist = GUICtrlCreateCombo("",20,60,290,149,-1,512) $bconnect = GUICtrlCreateButton("Connect To PC",20,255,290,30,-1,-1) GUICtrlSetFont(-1,12,400,0,"MS Sans Serif") $pwdinput = GUICtrlCreateInput("Input Password if different from default",20,220,290,28,-1,512) GUICtrlSetFont(-1,12,400,0,"MS Sans Serif") $bexit = GUICtrlCreateButton("E X I T",110,301,100,57,-1,-1) GUISetState(@SW_SHOW) ;Get Items from files $file = @ScriptDir & "\IDs\TVid.ini" Dim $newvalue, $userlist, $IDs, $userlist[10], $IDs[10] $sections = IniReadSectionNames($file) If @error Then MsgBox(4096, "", "Error occured, probably no INI file.") Else For $i = 1 To $sections[0] $newvalue = $newvalue & $sections[$i] & "|" Next GUICtrlSetData($namelist, StringTrimRight($newvalue, 1)) EndIf while 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Exit() Case $bexit _Exit() case $bconnect Connection() case $bsearch Case $namelist ConsoleWrite("Selected: " & GUICtrlRead($namelist) & @CRLF) EndSwitch WEnd Func Searcher() ;This is where I need it to find rather which item in the list is selected and then display its user name. Exit ;Erase or comment upon finished code EndFunc Func Connection() Exit ;Erase or comment upon finished code EndFunc Func _Exit() Exit EndFunc Queener 1 Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted February 16, 2015 Moderators Solution Share Posted February 16, 2015 asianqueen, Just look for the combo being actioned - no need for the input or button: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> HotKeySet("{ESC}", "_Exit") $TVID = GUICreate("TVID", 331, 374, -1, -1, -1, -1) GUISetFont(12, 400, 0, "MS Sans Serif") $namelist = GUICtrlCreateCombo("", 20, 60, 290, 149, -1, 512) $bconnect = GUICtrlCreateButton("Connect To PC", 20, 255, 290, 30, -1, -1) $pwdinput = GUICtrlCreateInput("Input Password if different from default", 20, 220, 290, 28, -1, 512) $bexit = GUICtrlCreateButton("E X I T", 110, 301, 100, 57, -1, -1) GUISetState(@SW_SHOW) ;Get Items from files $file = @ScriptDir & "\TVid.ini" Dim $newvalue, $userlist, $IDs, $userlist[10], $IDs[10] $sections = IniReadSectionNames($file) If @error Then MsgBox(4096, "", "Error occured, probably no INI file.") Else For $i = 1 To $sections[0] $newvalue = $newvalue & $sections[$i] & "|" Next GUICtrlSetData($namelist, StringTrimRight($newvalue, 1)) EndIf While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $bexit ; Multiple items are allowed here <<<<<< _Exit() Case $bconnect Connection() Case $namelist ; Combo actioned <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< MsgBox($MB_SYSTEMMODAL, "Username", IniRead($file, GUICtrlRead($namelist), "User", "Error")) EndSwitch WEnd Func Connection() Exit ;Erase or comment upon finished code EndFunc ;==>Connection Func _Exit() Exit EndFunc ;==>_Exit You will have to amend your ini file to use "=" rather then ":", otherwise you will need to write your own function instead of using IniRead. M23 Queener 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Queener Posted February 16, 2015 Author Share Posted February 16, 2015 (edited) I see... The reason I'm using a button is because I plan to use it to call a function. For example: If John is selected, call function connect to his pc, etc... So incase if I accidently click on James, I can cancel the msgbox and it does nothing. Else if I click Yes, it calls the function. Let me know if this isn't understantable so I can rephrase it. So in my opinion, I would think it's close to: if GUICtrlRead($namelist) == IniRead($file, "Justin", "") then MsgBox(0, "Justin Username is Jhon", "Bingo", 2) but it doesn't work. Edited February 16, 2015 by asianqueen Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.") Link to comment Share on other sites More sharing options...
kylomas Posted February 16, 2015 Share Posted February 16, 2015 OK, now that you've defined what you want to do, what is your question? Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Queener Posted February 16, 2015 Author Share Posted February 16, 2015 (edited) OK, now that you've defined what you want to do, what is your question? I think I resolved my issue, but run into something weird. It works, but why does it prompt me 3 times with this code? I know in the ini files; it contain 3 section, but shouldn't it match $namelist to one of those 3 section ini only? $bArray = IniReadSectionNames($file) if not @error Then for $a = 1 to $bArray[0] if GUICtrlRead($namelist) = $bArray[2] Then MsgBox(0, "Got It", "Bingo", 2) Next EndIf EDIT: Figured... I need to put the code outside the loop... hahahaaa dumb me! Thanks Melba and Geir. Edited February 16, 2015 by asianqueen Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.") 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