timdecker Posted April 21, 2015 Share Posted April 21, 2015 Whenever I load a file initially, everything is just fine. The problem arises when I wish to select another file..... Problem 1: Upon selecting another file, if I interact with the listview, it causes the data to disappear. Problem 2: Not only does the data disappear; but, if I have different headers in my csv, that gets all jacked-up as well. NOTE: This only occurs when pressing the button "Load File". Code: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Compression=4 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <file.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <Array.au3> #include <ComboConstants.au3> #include <GuiComboBox.au3> #include <StaticConstants.au3> Global $a_csv Global $listview Global $checkboxName Global $iCount Global $runProg Global $acheck Global $mapColumn Global $runProg Global $selectInstrument Global $selectFile Global $s_Path Global $sampleInputBox ;Global $iLVStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS) ;Global $iLVExtStyle = BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT) Global $selectAll Global $clearAll $s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "comma seperated values (*.csv)") If @error Then MsgBox(4096, "", "No File(s) chosen") Exit Else _FileReadToArray($s_Path, $a_csv) buildGUI() EndIf Func buildGUI() Local $sDrive, $sDir, $sFilename, $sExtension _PathSplit($s_Path,$sDrive, $sDir, $sFilename, $sExtension) GUICreate("THOTH - Auto File Name Creator for Instrument", 900, 450, -1, -1) ;$listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210,$iLVStyle,$iLVExtStyle) $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210) GUICtrlCreateLabel("Select a sample file:", 450, 40, 200) $sampleInputBox = GUICtrlCreateInput($sFilename&$sExtension,450,60,180,20) $loadNewFile = GUICtrlCreateButton("Load File", 450, 85) GUICtrlCreateLabel("Select an instrument:", 700, 40, 200) $selectInstrument = GUICtrlCreateCombo("", 700, 60, 180, 25) GUICtrlSetData(-1, "dummy|TGA-100|TGA-200|AUTOCAT-100|AUTOCAT-200") $checkboxName = StringSplit($a_csv[1], ",") $iCount = $checkboxName[0] ;creating buttons $runProg = GUICtrlCreateButton("Run Program", 530, 175, 250, 50) GUICtrlSetState($runProg, $GUI_DISABLE) ;$selectAll = GUICtrlCreateButton("Select All", 300, 230, 100, 30) ;$clearAll = GUICtrlCreateButton("Clear All", 300, 270, 100, 30) ;Building the checkboxes DYNAMICALLY....may need to switch to forced checkbox name ;Store controIDs of the checkboxes Global $aCheck[$iCount + 1] Global $mapColumn[$iCount + 1] For $j = 1 To $iCount $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30) GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED) Next For $i = 2 To UBound($a_csv) - 1 $s_temp = StringReplace($a_csv[$i], ",", "|") GUICtrlCreateListViewItem($s_temp, $listview) Next Global $aOut[''][''] For $i = 2 to $a_csv[0] $aLine = stringsplit($a_csv[$i] , ",",3) If ubound($aLine) > ubound($aOut , 2) Then redim $aOut[$i][ubound($aLine)] _ArrayAdd($aOut , $a_csv[$i] , 0 , ",") Next Local $idCancelbutton = GUICtrlCreateButton("Exit", 700, 400, 180, 30) GUISetState(@SW_SHOW) ;GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $runProg If GUICtrlRead($selectInstrument) <> "" Then copyToInput() Else MsgBox(0, "", "Select and Instrument") EndIf Case $loadNewFile _loadNewFile() GUICtrlSetState($runProg, $GUI_DISABLE) Case $GUI_EVENT_CLOSE, $idCancelbutton ExitLoop Case Else For $i = 1 To $iCount If $msg = $aCheck[$i] Then If GUICtrlRead($msg) = 1 Then GUICtrlSetState($runProg, $GUI_ENABLE) Else GUICtrlSetState($runProg, $GUI_DISABLE) EndIf ExitLoop EndIf Next EndSwitch WEnd GUIDelete() EndFunc Func _loadNewFile() Local $sDrive, $sDir, $sFilename, $sExtension $selectFile = FileOpenDialog("Select a file with a sample list...", @ScriptDir, "Text (*.csv;*.txt)") If @error Then MsgBox(4096, "", "No File(s) chosen") Else cleanListview() _PathSplit($selectFile,$sDrive, $sDir, $sFilename, $sExtension) GUICtrlSetData($sampleInputBox, $sFilename & $sExtension) _FileReadToArray($selectFile,$a_csv) $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210) For $i = 2 To UBound($a_csv) - 1 $s_temp = StringReplace($a_csv[$i], ",", "|") GUICtrlCreateListViewItem($s_temp, $listview) Next $checkboxName = StringSplit($a_csv[1], ",") $iCount = $checkboxName[0] For $j = 1 To $iCount $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30) GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED) Next EndIf EndFunc Func copyToInput() Select Case GUICtrlRead($selectInstrument) = "dummy" $textPos_1 = 4 $buttonClick_1 = 6 $buttonClick_2 = 2 $title_1 = "HPOV" $title_2 = "Job" Case GUICtrlRead($selectInstrument) = "TGA-100" $textPos_1 = 1161 $buttonClick_1 = 1152 $title_1 = "(METTLER) - TGA-100A with gas box" Case GUICtrlRead($selectInstrument) = "TGA-200" $textPos_1 = 1161 $buttonClick_1 = 1152 $title_1 = "(METTLER) - TGA-200A with gas box" Case GUICtrlRead($selectInstrument) = "AUTOCAT-100" $textPos_1 = 4 $buttonClick_1 = 6 $title_1 = "HPOV" Case GUICtrlRead($selectInstrument) = "AUTOCAT-200" $textPos_1 = 1161 $buttonClick_1 = 1152 $title_1 = "FIND AUTOCAT-200 NAME!" EndSelect $allRows = _GUICtrlListView_GetItemCount($listview) Local $iState = WinGetState($title_1) ;ConsoleWrite($iState) If BitAND($iState,1) <> 1 then MsgBox(0, "Application Not Open", "Make sure the instrument application" & @CRLF & "window is open...") Else For $rows = 0 to $allRows-1 $material_name = _GUICtrlListView_GetItem($listview, $rows, 0) $letter = _GUICtrlListView_GetItem($listview, $rows, 3) If GUICtrlRead($aCheck[1]) <> 1 and GUICtrlRead($aCheck[4]) <> 1 then continueloop If GUICtrlRead($aCheck[1]) = 1 Then controlsettext($title_1, "", $textPos_1, $material_name[3]) EndIf #cs - 2nd input box If GUICtrlRead($aCheck[4]) = 1 Then controlsettext($title, "", $textPos_2, $letter[3]) endif #ce controlclick($title_1, "", $buttonClick_1) Sleep(2000) ;there you can put some sleep(5000) = 5seconds, more or less, if u know exact applications processing time for this operation ;or ControlGetText("Myapplication title", "", CONTROL_WHICH_CHANGES_AFTER_BUTTONPRESS) and compare to older reads If IsDeclared("title_2") and IsDeclared("buttonClick_2") Then controlclick($title_2, "", $buttonClick_2) Sleep(2000) EndIf ;there you can put some sleep(5000) = 5seconds, more or less, if u know exact applications processing time for this operation ;or ControlGetText("Myapplication title", "", CONTROL_WHICH_CHANGES_AFTER_BUTTONPRESS) and compare to older reads If msgbox(1,"", "You Shall Not Pass!" & @CRLF & "Ok actually you can, just press something") = 2 then ExitLoop EndIf Next EndIf EndFunc Func cleanListview() _GUICtrlListView_DeleteAllItems($listview) For $i = 1 To $iCount GUICtrlDelete($acheck[$i]) Next EndFunc Sample CSV1: material_name,material_alias,period,letter HT-000001333,,r1,C7 dummy1,,,C8 dummy2,,,D1 dummy3,,,D2 dummy4,,,D3 dummy5,,,D4 RS-000001336,,r2,D5 dummy7,,,D6 Sample CSV2: Building,Room,Network Building1,Room1,Network_Path1 Building2,Room2,Network_Path2 Building3,Room3,Network_Path3 Building4,Room4,Network_Path4 Building5,Room5,Network_Path5 Thanks again AutoIT Community! Tim Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted April 21, 2015 Moderators Solution Share Posted April 21, 2015 timdecker,You never destroy the existing ListView before creating another. If I replace the cleanListview call with GUICtrlDelete($listview) it works for me.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
timdecker Posted April 21, 2015 Author Share Posted April 21, 2015 timdecker, You never destroy the existing ListView before creating another. If I replace the cleanListview call with GUICtrlDelete($listview) it works for me. M23 Thanks Melba23! I was using "_GUICtrlListView_DeleteAllItems" for some odd reason, and I am not sure why.... Either way, it works now. Tim 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