Jump to content

Help Getting Selected Text In Listbox Function


Recommended Posts

Hello everyone. I'm having a problem with the ListBox stuff.

See if you can try to help me im a little new but it isn't working

My problem: I have this listbox, and im tring to get the text from the listbox

when the listbox is click, like it has:

Name1

Name2

And in my loop, I have Case $ListBox or whatever, and then I need to get the selected

items text, and give it as a debug messagebox for now. I try to use Case $ListBox

and it never does anything. Check out my code below

$TransGUI = GUICreate("Transactions", 393, 585, 627, 155)
$Date1 = GUICtrlCreateDate("", 184, 8, 202, 21)
$ListBox = GUICtrlCreateList("", 8, 40, 377, 539)
;~ $ListBox = _GUICtrlListBox_Create($TransGUI, "", 8, 40, 377, 539)
;~ $List1 = GUICtrlCreateList("", 8, 40, 377, 539)
$Label1 = GUICtrlCreateLabel("Load Transactions For:", 8, 8, 113, 17)
GUISetState()

Heres my loop

While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
Case $Date1
            $Date = _DateToNumber(GUICtrlRead($Date1))
            If FileExists(@ScriptDir&"\Point Of Sale\Logs\"&$Date) Then
                $CurrentFiles = _FileListToArray(@ScriptDir&"\Point Of Sale\Logs\"&$Date)
                _GUICtrlListBox_ResetContent($ListBox)
                For $l = 1 To $CurrentFiles[0]
                    $File=""
                    $File = StringTrimRight($CurrentFiles[$l], 4)
                    _GUICtrlListBox_AddString($ListBox, $File)
                Next
            EndIf
Case $ListBox
            MsgBox(0, "", "Clicked")
endswitch
wend

And the functions needed:

Func _GetNumberMonthFromMonth($_a_Month)
    If $_a_Month = "January" Then Return("01")
    If $_a_Month = "February" Then Return("02")
    If $_a_Month = "March" Then Return("03")
    If $_a_Month = "April" Then Return("04")
    If $_a_Month = "May" Then Return("05")
    If $_a_Month = "June" Then Return("06")
    If $_a_Month = "July" Then Return("07")
    If $_a_Month = "August" Then Return("08")
    If $_a_Month = "September" Then Return("09")
    If $_a_Month = "October" Then Return("10")
    If $_a_Month = "November" Then Return("11")
    If $_a_Month = "December" Then Return("12")
EndFunc
Func _DateToNumber($_InfoReturnedFromDateCtrl)
    $ActualDate=""
    $_String = StringSplit($_InfoReturnedFromDateCtrl, " ")
    $Day = StringTrimRight($_String[3], 1)
    $Month = _GetNumberMonthFromMonth($_String[2])
    $ActualDate = $Month&"-"&$Day&"-"&$_String[4]
    Return $ActualDate
EndFunc

I need when the listbox is clicked to do a _filelisttoarray() of the logs and if the listbox item is in there ( it will be ) load the info from the file ( i can do that )

Edited by d2addict4
Link to comment
Share on other sites

Since nobody feels like helping...i just tried this:

Case $ListBox
            MsgBox(0, "", "Clicked")
            $Text = _GUICtrlListBox_GetSelItemsText($ListBox)
            MsgBox(0, "", $Text)
            MsgBox(0, "", $Text[0])
            For $z=1 To $Text[0]
            MsgBox(0, "", $Text[$z])
            Next

And it still doesn't work.

$Text returns nothing

$Text[0] returns 0 ( nothing clicked )

so...if anyone wants to help me now that I have tried...AGAIN

is there like some reason no one wants to help me? is this program agenist the rules or something

Link to comment
Share on other sites

  • Moderators

Since nobody feels like helping...i just tried this:

Case $ListBox
            MsgBox(0, "", "Clicked")
            $Text = _GUICtrlListBox_GetSelItemsText($ListBox)
            MsgBox(0, "", $Text)
            MsgBox(0, "", $Text[0])
            For $z=1 To $Text[0]
            MsgBox(0, "", $Text[$z])
            Next

And it still doesn't work.

$Text returns nothing

$Text[0] returns 0 ( nothing clicked )

so...if anyone wants to help me now that I have tried...AGAIN

is there like some reason no one wants to help me? is this program agenist the rules or something

I'll explain this as well as I can.

We help those we want when we want and how we want. Just because you need or want something doesn't mean you'll get it. Anyone that chooses to help, helps at their expense to enlighten you, as you haven't spent a dime for support.

With that in mind, don't bump your topic more than once in a 24 hour period if no responses have been made, and don't bump it more than 3 times, after 3 times, the topic is considered dead.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

If you were using the one with the debug messages, that was coming from the WM_COMMAND function, which will show you things such as "Double Click".

#include <guilistbox.au3>
#include <file.au3>
Global $hListBox
$TransGUI = GUICreate("Transactions", 393, 585, 627, 155)
$Date1 = GUICtrlCreateDate("", 184, 8, 202, 21)
;~ $hListBox = GUICtrlCreateList("", 8, 40, 377, 539)
$hListBox = _GUICtrlListBox_Create($TransGUI, "This is text", 8, 40, 377, 539)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
;~ $List1 = GUICtrlCreateList("", 8, 40, 377, 539)
$Label1 = GUICtrlCreateLabel("Load Transactions For:", 8, 8, 113, 17)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Date1
            $Date = _DateToNumber(GUICtrlRead($Date1))
            If FileExists(@ScriptDir & "\Point Of Sale\Logs\" & $Date) Then
                $CurrentFiles = _FileListToArray(@ScriptDir & "\Point Of Sale\Logs\" & $Date)
                _GUICtrlListBox_ResetContent($hListBox)
                For $l = 1 To $CurrentFiles[0]
                    $File = ""
                    $File = StringTrimRight($CurrentFiles[$l], 4)
                    _GUICtrlListBox_AddString($hListBox, $File)
                Next
            EndIf
    EndSwitch
WEnd

Func _GetNumberMonthFromMonth($_a_Month)
    If $_a_Month = "January" Then Return ("01")
    If $_a_Month = "February" Then Return ("02")
    If $_a_Month = "March" Then Return ("03")
    If $_a_Month = "April" Then Return ("04")
    If $_a_Month = "May" Then Return ("05")
    If $_a_Month = "June" Then Return ("06")
    If $_a_Month = "July" Then Return ("07")
    If $_a_Month = "August" Then Return ("08")
    If $_a_Month = "September" Then Return ("09")
    If $_a_Month = "October" Then Return ("10")
    If $_a_Month = "November" Then Return ("11")
    If $_a_Month = "December" Then Return ("12")
EndFunc   ;==>_GetNumberMonthFromMonth

Func _DateToNumber($_InfoReturnedFromDateCtrl)
    $ActualDate = ""
    $_String = StringSplit($_InfoReturnedFromDateCtrl, " ")
    $Day = StringTrimRight($_String[3], 1)
    $Month = _GetNumberMonthFromMonth($_String[2])
    $ActualDate = $Month & "-" & $Day & "-" & $_String[4]
    Return $ActualDate
EndFunc   ;==>_DateToNumber

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
    If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word

    Switch $hWndFrom
        Case $hListBox, $hWndListBox
            Switch $iCode
                Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box
                    MsgBox(64, "Info", "You double clicked the list box.")
                    ; If you want do something with 2 clicks, do something here
            EndSwitch
    EndSwitch
    ; Proceed the default Autoit3 internal message commands.
    ; You also can complete let the line out.
    ; !!! But only 'Return' (without any value) will not proceed
    ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

sorry i thought you people actually wanted to help. this doesnt seem hard either but theres many views and no one wants to enlighten me.

Enlightenment should be sought in the helpfile first and foremost.

MsgBox(0, "", "Selected " & GUICtrlRead($ListBox))

_GUICtrlListBox_GetSelItemsText/_GUICtrlListBox_GetSelCount don't work on singleselect listbox.

"be smart, drink your wine"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...