topgundcp Posted January 17, 2020 Posted January 17, 2020 (edited) Hi, This is my very first post in this forum and am also new with Autoit programming so be easy on me. Below is the code that I am trying to get the index of the item selected. No problem getting the text. Case $listEdition ; handle of the list local $index=0 $item=GUICTRLRead($listEdition) ; This will return the text in the list ; ============== The loop below always fails ================== ; Meaning _GUICtrlListView_GetItemSelected($listEdition, $i) always return FALSE. WHY ??????? For $i = 0 To $editionArray[0] - 1 ; The content of the list in an array where editionArray[0] contains total count of items If _GUICtrlListView_GetItemSelected($listEdition, $i) Then $index = $i exitloop EndIf Next ;=================================================== ConsoleWrite( "Select Edition: " & $item & " index: " & $index & @CR) ....... Please look at the comments in the code & the pix attached. _GUICtrlListView_GetItemSelected($listEdition, $i) always returns FALSE. Another problem is on the list. It also populate the total count of items from the Array. How can I skip this item from populating to the list ?. Please advise and thanks Edited January 17, 2020 by topgundcp
alienclone Posted January 17, 2020 Posted January 17, 2020 what is $editionArray topgundcp 1 If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version
topgundcp Posted January 17, 2020 Author Posted January 17, 2020 EditionArray is what you see on the list box. Take a look at the picture where Edition[0] = 7 ie. the number of items on the list.
alienclone Posted January 17, 2020 Posted January 17, 2020 i dont see where you define $editionArray your comment says editionArray contains the total count of items, but i dont see in your script where you tell it that. topgundcp 1 If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version
Nine Posted January 17, 2020 Posted January 17, 2020 @topgundcp You would help us in making a runable snippet of your code instead of showing us only a small part of the script. You would get much more help that way. Help us to help you... topgundcp 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
pixelsearch Posted January 17, 2020 Posted January 17, 2020 @topgundcp: the function used doesn't seem to be the good one : _GUICtrlListView_GetItemSelected() As the title thread & the picture you posted indicate a list box (not a listview) then this instruction should be used instead : _GUICtrlListBox_GetCurSel($listEdition) topgundcp 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
topgundcp Posted January 17, 2020 Author Posted January 17, 2020 Thank you guys. As you can see I am quite new to this and this is my 2nd day learning Autoit so I am not familiar with all the functions available. Haven't done any programming in 15 years. and thanks to @pixelsearch. I shall try and report back. However, I play around and get it to work in a dirty way by comparing the string in the Array and the text from the list, not really efficient though. and here's the code: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=J:\Autoit Projects\test.kxf $TEST = GUICreate("TEST", 275, 310, -1, -1) $Exit = GUICtrlCreateButton("Exit", 77, 240, 105, 33) GUICtrlSetFont(-1, 9, 800, 0, "Arial Narrow") $listEdition = GUICtrlCreateList("", 40, 48, 193, 160, BitOR($LBS_NOTIFY,$LBS_EXTENDEDSEL,$WS_VSCROLL)) $LEdit = GUICtrlCreateLabel("Windows 10 Edition", 40, 24, 119, 20) GUICtrlSetFont(-1, 10, 400, 0, "Arial") GUICtrlSetColor(-1, 0x000080) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ;================================ Start ======================================= #include <Array.au3> #include <File.au3> #include <StringConstants.au3> #include <MsgBoxConstants.au3> #include <GuiListView.au3> ; Run(@ComSpec & ' /c dism /Get-WimInfo /WimFile:J:\BatchFiles\install.esd | find /i "Description" > ~A~_edition.txt', "",@SW_HIDE) ;================================================================ ; Count no. of lines from text file to allocate Array size Global $editionCount = _FileCountLines ( "~A~_edition.txt" ) ;================================================================ Global $editionArray[$editionCount] local $lines ;================================================================ _FileReadToArray("~A~_edition.txt", $editionArray) ; and the rest is each line from text file for $i=0 to UBound($editionArray) -1 $editionArray[$i] = StringStripWS ( $editionArray[$i], $STR_STRIPLEADING + $STR_STRIPTRAILING) Next $Lines = _ArrayToString($editionArray, "|", 1,Ubound($editionArray)-1, @CRLF) $Lines = StringReplace($Lines, "Description : ", "",0) ;ConsoleWrite($Lines & @CR) GuiCtrlSetData($ListEdition, $Lines) $editionArray = StringSplit($Lines,"|",$STR_CHRSPLIT) $editionCount = Ubound($editionArray) ;_ArrayDisplay($editionArray, "Edition " & $editionCount) ;=============================================================================== While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $listEdition ; handle of the list local $index=0 $item=GUICtrlRead($listEdition) ; This will return the text in the list for $i=0 to Ubound($editionArray) - 1 if StringCompare($item, $editionArray[$i]) = 0 Then $index = $i ExitLoop endif Next ConsoleWrite( "Edition Selected: " & $Item & " Index: " & $index &@CR) #cs ; ============== The loop below always fails ================== ; Meaning _GUICtrlListView_GetItemSelected($listEdition, $i) always return FALSE. WHY ??????? For $i = 0 To $editionArray[0] - 1 ; The content of the list in an array where editionArray[0] contains total count of items If _GUICtrlListView_GetItemSelected($listEdition, $i) Then $index = $i exitloop EndIf Next ;=================================================== #ce Case $exit exit EndSwitch WEnd The content of the txt file getting from windows command, I commented out on top since I don't know if you have the Windows Installation media.: Description : Windows 10 Home Description : Windows 10 Home N Description : Windows 10 Home Single Language Description : Windows 10 Education Description : Windows 10 Education N Description : Windows 10 Pro Description : Windows 10 Pro N
topgundcp Posted January 17, 2020 Author Posted January 17, 2020 55 minutes ago, pixelsearch said: @topgundcp: the function used doesn't seem to be the good one : _GUICtrlListView_GetItemSelected() As the title thread & the picture you posted indicate a list box (not a listview) then this instruction should be used instead : _GUICtrlListBox_GetCurSel($listEdition) Perfect. It works Thank you.
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