Jump to content
topgundcp

Get index of the item selected from list box

Recommended Posts

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

2020-01-16_201900.jpg

Edited by topgundcp

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.


If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
    EndIf

"Yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results

Share this post


Link to post
Share on other sites

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:

#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


 

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

  • Similar Content

    • By PeterVerbeek
      This topic give you access to an AutoIt functions library I maintain which is called PAL, Peter's AutoIt Library. The latest version 1.19 contains 194 functions divided into these topics:
      window and screen mouse and GUI GUI controls logics and mathematics string, xml string and file string dialogues and progress bars data lists: lists, stacks, shift registers and key maps (a.ka. dictionaries) miscellaneous: logging/debugging, process and system info A lot of these functions were created in the development of Peace, Peter's Equalizer APO Configuration Extension, which is a user interface for the system-wide audio driver called Equalizer APO.
    • By n0ktar
      is it possible to make a wall chams in rainbow six siege using autoit scripts? tell me please and how . 
    • By Rskm
      Hi, I am using excel as input media for my program. The excel file (i tried with .xls, .xlsx and .xlsm format) has inputs which the autoit script reads during the run and performs few calculations. Some times (not always), after the run, when i try to open the excel file manually, the file doesnt open at all in excel. see the screenshot attached. However, if the execute the autoit script, the scripts still reads the existing data from that excel and performs the calcs. I copied the excel file to another computer and there too, it doesnt open.  So, after this, i cannot edit the excel forever (if i need to change any inputs). It is only this particular file that got affected. other excel files works normal.  What could be the problem here.  please help as this is a new challenge for me during my program development. 

    • By TheAutomator
      Hi everyone!

      I'm using AutoIt for several years now and I really get the hang of it!
      I'm quite the curious OCD perfectionist kind of guy, so I can't help wondering..
      what would be the best way to program stuff for the compiler / interpreter / scripting engine?
      We're talking about the inner workings of the AutoIt's core here, and how to give it as less friction as possible but also take care of the machine running the script.
      For example,
      Imagine a script where we would constantly have to assign a Boolean value to a variable:
      ; A: local $bool = false $bool = true $bool = true $bool = false ; B: local $bool = false check(true) check(true) check(false) func check($b) if $bool = $b then return $bool = $b endfunc In this case, would it be better to just overwrite (A) the variable or first check if we really need to (B)?
      What would be best for the computers memory if it had to do this for a year non stop?
      Another example, imagine you're writing a function with an if statement.
      If you would look under the hood of AutoIt, what would be the best way to give your computer as less work / code nesting stack filling as possible:
      ; A: func decide($b_Input) if $b_Input then ;do something else ;do something else endif endfunc ; B: func decide($b_Input) if $b_Input then ;do something return endif ;do something else endfunc Last one for now:
      ; A: while 1 ; do stuff wend ; B: while true ; do stuff wend Isn't AutoIt taking an extra step in converting 1 to a Boolean in example (A)?
      Or is it the other way around and does the (B) way make AutoIt first convert a keyword (true or false) to a numerical value (0 or 1).
      I think this kinda detail stuff is quite interesting, makes me wonder how AutoIt converts and runs our code.
      What are your opinions on this topic?
      Any coders who know more about the inner workings of AutoIt?
      Any people like me who ask themselves similar questions (with examples)?

      Let me know! 😉
    • By v120
      Rapid Fire Mouse Hack Script
      *snip*
       
×
×
  • Create New...