goss34 Posted October 26, 2011 Share Posted October 26, 2011 Hi Guys, I am writing a script that will check a set of folders to populate a list with available data. Here is how i create the liveview: $listview = GUICtrlCreateListView("", 10, 30, 330, 250) _GUICtrlListView_InsertColumn($listview, 0, "Client Name", 160) _GUICtrlListView_InsertColumn($listview, 1, "Available P11D Data", 160) If FileExists($Location & "2005-2006\P11DDATA.MDB") Then GUICtrlCreateListViewItem($Client & "|2005-2006", $listview) EndIf If FileExists($Location & "2006-2007\P11DDATA.MDB") Then GUICtrlCreateListViewItem($Client & "|2006-2007", $listview) EndIf Next here i want to select one of the list view items and when i click open it will run the relevant command. GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState() Do $msg = GUIGetMsg() If $msg = $open Then $iSelect = ControlListView($hGUI, "", $listview, "GetSelected") If $iSelect = "" Then MsgBox(0, "ERROR!", "No data selected, the program will now exit.") Exit EndIf If $iSelect = 0 Then Run('"C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" /runtime /wrkgrp "' & $Location & '2005-2006\P11D.mdw" "' & $Location & '2005-2006\P11DSys.mdb"') EndIf If $iSelect = 1 Then MsgBox(0, "Pretend Run", "2006-2007") EndIf The problem i am having is with this line: $iSelect = ControlListView($hGUI, "", $listview, "GetSelected") Depending on which item is seleted it flags it using a 0, 1, 2 onwards where as i want it to get the text from the list view because if all the data doesnt exists the numbers are not in the correct order so it will run the wrong command. I have tried GetText but either i dont understand the syntax so am doing it wrong or it just doesnt work (most likely the first :-() Can anyone help? Thank you P.S. If anyone can identify why this line doesnt work properly that would be appreciated: If $iSelect = "" Then MsgBox(0, "ERROR!", "No data selected, the program will now exit.") Exit EndIf If i dont have the "Exit" command it automatically launches the next command down which it shouldnt as that isnt selected! Link to comment Share on other sites More sharing options...
water Posted October 26, 2011 Share Posted October 26, 2011 To get the text of the selected item use: $iSelect = ControlListView($hGUI, "", $listview, "GetSelected") $sSelect = ControlListView($hGUI, "", $listview, "GetText", $iSelect) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
goss34 Posted October 26, 2011 Author Share Posted October 26, 2011 To get the text of the selected item use: $iSelect = ControlListView($hGUI, "", $listview, "GetSelected") $sSelect = ControlListView($hGUI, "", $listview, "GetText", $iSelect) Thank you Water, I always feel a little dumb when you point it out so simply! Any chance anyone can help with this bit: If $msg = $open Then $iSelect = ControlListView($hGUI, "", $listview, "GetSelected") $sSelect = ControlListView($hGUI, "", $listview, "GetText", $iSelect, 1) ;ConsoleWrite("Debug: $iSelect = " & $iSelect & @LF) ;ConsoleWrite("Debug: $sSelect = " & $sSelect & @LF) If $sSelect = "" Then MsgBox(0, "ERROR!", "No data selected, the program will now exit.") Exit EndIf If $sSelect = "2005-2006" Then Run('"C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" /runtime /wrkgrp "' & $Location & '2005-2006\P11D.mdw" "' & $Location & '2005-2006\P11DSys.mdb"') EndIf The problem that if nothing is selected when you press the "Open" button it displays the msgbox then jumps and opens the next line down instead of doing nothing. I can only get it to exit after the msgbox otherwise the program is just no good as it will keep opening the wrong databases. Thanks Link to comment Share on other sites More sharing options...
goss34 Posted October 28, 2011 Author Share Posted October 28, 2011 Can anyone help me with the post above? Thank you Link to comment Share on other sites More sharing options...
Zedna Posted October 28, 2011 Share Posted October 28, 2011 Use ExitLoop instead of Exit. Your code snippet is insufficient for correct help. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
goss34 Posted October 28, 2011 Author Share Posted October 28, 2011 Hi Zedna, I tried changing it to ExitLoop but it still launches the second line. Here is the full code: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <GuiListView.au3> Opt('MustDeclareVars', 1) FileInstall("C:\Loading.gif", @TempDir & "\Loading.gif") FileInstall("C:\Assessa.ico", @TempDir & "\Assessa.ico") TraySetIcon (@TempDir & "\Assessa.ico") SplashImageOn("Please Wait...", @TempDir & "\Loading.gif", 465, 350) Sleep(3000) SplashOff() FileDelete(@TempDir & "\Loading.gif") Assessa() Func Assessa() Local $listview, $msg, $open, $hGUI, $iSelect, $Location, $Client, $sSelect $Client = $CmdLine[1] $Location = "J:\" & $Client & "\Assessa\" $hGUI = GUICreate("Assessa Launcher", 350, 320, -1, -1, -1, $WS_EX_ACCEPTFILES) ;$listview = GUICtrlCreateListView("Client Name|Available P11D Data", 10, 30, 330, 250) $listview = GUICtrlCreateListView("", 10, 30, 330, 250) _GUICtrlListView_InsertColumn($listview, 0, "Client Name", 160) _GUICtrlListView_InsertColumn($listview, 1, "Available P11D Data", 160) GUICtrlCreateLabel("Select the data you wish to view", 10, 10) $Open = GUICtrlCreateButton("Open", -1, 290, 100, 20) If FileExists($Location & "2005-2006\P11DDATA.MDB") Then GUICtrlCreateListViewItem($Client & "|2005-2006", $listview) EndIf If FileExists($Location & "2006-2007\P11DDATA.MDB") Then GUICtrlCreateListViewItem($Client & "|2006-2007", $listview) EndIf If FileExists($Location & "2007-2008\P11DDATA.MDB") Then GUICtrlCreateListViewItem($Client & "|2007-2008", $listview) EndIf If FileExists($Location & "2008-2009\P11DDATA.MDB") Then GUICtrlCreateListViewItem($Client & "|2008-2009", $listview) EndIf If FileExists($Location & "2009-2010\P11DDATA.MDB") Then GUICtrlCreateListViewItem($Client & "|2009-2010", $listview) EndIf If FileExists($Location & "2010-2011\P11DDATA.MDB") Then GUICtrlCreateListViewItem($Client & "|2010-2011", $listview) EndIf GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState() ;Show the GUI Do $msg = GUIGetMsg() If $msg = $open Then $iSelect = ControlListView($hGUI, "", $listview, "GetSelected") $sSelect = ControlListView($hGUI, "", $listview, "GetText", $iSelect, 1) ;ConsoleWrite("Debug: $iSelect = " & $iSelect & @LF) ;ConsoleWrite("Debug: $sSelect = " & $sSelect & @LF) If $sSelect = "" Then MsgBox(0, "ERROR!", "No data selected, the program will now exit.") EndIf If $sSelect = "2005-2006" Then Run('"C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" /runtime /wrkgrp "' & $Location & '2005-2006\P11D.mdw" "' & $Location & '2005-2006\P11DSys.mdb"') EndIf If $sSelect = "2006-2007" Then MsgBox(0, "Pretend Run", "2006-2007") EndIf If $sSelect = "2007-2008" Then Run('"C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" /runtime /wrkgrp "' & $Location & '2007-2008\P11D.mdw" "' & $Location & '2007-2008\P11DSys.mdb"') EndIf If $sSelect = "2008-2009" Then MsgBox(0, "Pretend Run", "2008-2009") EndIf If $sSelect = "2009-2010" Then MsgBox(0, "Pretend Run", "2009-2010") EndIf If $sSelect = "2010-2011" Then MsgBox(0, "Pretend Run", "2010-2011") EndIf ;ConsoleWrite("Debug: $iSelect = " & $iSelect & @LF) EndIf Until $msg = $GUI_EVENT_CLOSE EndFunc FileDelete(@TempDir & "\Assessa.ico") Thank you Link to comment Share on other sites More sharing options...
goss34 Posted October 28, 2011 Author Share Posted October 28, 2011 I have been trying to troubleshoot it further using the consolewrite lines i have commented out on the above script and it seems $sSelect always = the top item in the list as opposed to being empty or "". I have managed to put in a workaround but not sure why its not working like i intended if anyone can expand my knowledge that would be appreciated. See changes: If $iSelect = "" Then MsgBox(0, "ERROR!", "No data selected, the program will now exit.") EndIf If $iSelect = "" Then $sSelect = "" ;ConsoleWrite("Debug: $sSelect = " & $sSelect & @LF) MsgBox(0, "ERROR!", "No data selected, the program will now exit.") EndIf This works because the next time you select something in the listview and click open it rechecks the selected item and resets the value of the $sSelect variable. Thanks Link to comment Share on other sites More sharing options...
Zedna Posted October 28, 2011 Share Posted October 28, 2011 Use ExitLoop instead of Exit. Sorry my mistake, use ContinueLoop instead of Exit Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
goss34 Posted October 28, 2011 Author Share Posted October 28, 2011 Sorry my mistake, use ContinueLoop instead of ExitThats done it Zedna thank you. Why does it not continue the loop anyway? None of the other lines need me to do that. Thanks for your help. 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