Queener

ComboBox and selecting items

6 posts in this topic

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

#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.")

Share this post


Link to post
Share on other sites



This what you want?

#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
1 person likes this

Share this post


Link to post
Share on other sites

asianqueen,

Just look for the combo being actioned - no need for the input or button: :)

#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

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 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.")

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 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.")

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now