-
Posts
95 -
Joined
-
Last visited
Everything posted by timdecker
-
Problem: As soon as the script gets to a folder that does not contain a file I am searching for, it stops rather than continuing until it finds the next folder with the specified file. What is going on? Also, sometimes the files are in a folder one level down (of which I do not know the name of), how do drill down to the next folder to find the file if it is not in the original source folder? Thanks! #include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> #include <FileOperations.au3> Global $aPartial, $sFilePath = "arrlistTextFile.txt", $aFull = _FileListToArray("C:\SourceDir\",Default,$FLTA_FOLDERS), $sSourceDir = "C:\SourceDir\" Global $sDestination = "D:\DestinationDir\" CopyFiles() Func CopyFiles() _FileReadToArray($sFilePath, $aPartial) For $i = 0 To UBound($aPartial) - 1 $iIndex = _ArraySearch($aFull, $aPartial[$i], 0, 0, 0, 1) ; $iCompare = 1 executes a partial search If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "No match for: " & $aPartial[$i]) Else $createDir = $sDestination & $aPartial[$i] $sSourcePath = $sSourceDir & $aFull[$iIndex] $sFindFile2 = _FileListToArray($sSourcePath,"*TABWT*", Default, True) ) $_sFile2 = _ArrayDisplay($sFindFile2) EndIf Next EndFunc
-
[Error] Array var incorrect number of subs...
timdecker replied to timdecker's topic in AutoIt General Help and Support
Just saw that =) Thanks! -
#include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> #include <FileOperations.au3> Global $aPartial, $sFilePath = "arraylistofnumbers.txt", $aFull = _FileListToArray("C:\SourceDir\",Default,$FLTA_FOLDERS), $sSourceDir = "C:\SourceDir" Global $sDestination = "D:\DestinationDir" CopyFiles() Func CopyFiles() _FileReadToArray($sFilePath, $aPartial) For $i = 0 To UBound($aPartial) - 1 $iIndex = _ArraySearch($aFull, $aPartial[$i], 0, 0, 0, 1) ; $iCompare = 1 executes a partial search If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "No match for: " & $aPartial[$i]) Else ConsoleWrite($i& ":" & $aPartial[$iIndex] & @CRLF) EndIf Next EndFunc With the above I get the following error: What is going on? I know some of the data in my text file will not be in the Dir I am looking for, but isn't that what the @error is suppose to take care of? Why am I getting this error?
-
Copy List of Folders to New Dir
timdecker replied to timdecker's topic in AutoIt General Help and Support
Okay. Got it, but I am having an error on the loop: "Array variable has incorrect number of subscripts or subscript dimension range exceeded.:" -
Copy List of Folders to New Dir
timdecker replied to timdecker's topic in AutoIt General Help and Support
Again, thank you M23. I tried to use the following: FileCopy("S:source\" & $aFull[$iIndex] & "\INDATA*.xls", "C:\destination\" & $aPartial[$iIndex], $FC_OVERWRITE + $FC_CREATEPATH) But that did not work out as planned... -
Copy List of Folders to New Dir
timdecker replied to timdecker's topic in AutoIt General Help and Support
Thanks M23. I am stuck on the _ArraySearch part. I have my For loop setup, but not sure what to place inside of it to match the arrays and copy the folder. -
Copy List of Folders to New Dir
timdecker replied to timdecker's topic in AutoIt General Help and Support
Sorry, let me clarify. I have a text file that has the following: 3540 3565 3571 3582 3604 3614 I have folders for each of the following: C:\folder\exy-3540 kac\ C:\folder\exy-3565 cda\ etc. I would like to copy the above folders (based on the info in the text file) to another location. Please let me know if I need to clarify anything else. Thanks! -
I have a list of partial folder names in colB (e.g. "785A5", and the real folder name is "exy-78a5 blah random"). There are about 1500 folders like this. I would like to copy these folders to a new destination. Also, I only keep files in those folders that have a certain prefix, lets call that "indata", and either delete or not copy the other files in that folder. Out of all of that, I really just want to know how to copy folders from one location to another that I have a list of and only partially match. Thanks!
-
_GUICtrlListView_DeleteItemsSelected w/ Checkboxes
timdecker replied to timdecker's topic in AutoIt General Help and Support
Thank you for that kylomas, that worked! I tried multiple variations of that, but I guess not that combo.... Could someone explain this to me: For $i = $ItemCount - 1 to 0 step -1 Thanks! Tim Edit: Looking at it it, it makes sense now...but just to clarify the "Step - 1" part is saying to go in reverse, right? -
_GUICtrlListView_DeleteItemsSelected w/ Checkboxes
timdecker replied to timdecker's topic in AutoIt General Help and Support
I honestly think this is all I need: Local $ItemCount = _GUICtrlListView_GetItemCount($listview), $Checked[$ItemCount + 1] For $i = 0 To $ItemCount - 1 ; check all items in the lv and see if any are checked off If _GUICtrlListView_GetItemChecked($listview, $i) Then ConsoleWrite($i) EndIf Next EndFunc The consoleWrite here, returns the index of the rows. What I am unsure of is how to go in reverse (like you said). -
_GUICtrlListView_DeleteItemsSelected w/ Checkboxes
timdecker replied to timdecker's topic in AutoIt General Help and Support
I am fairly sure I understand what I am reading for the code.... If you look at my ConsoleWrite statement, it writes the line number of the row I selected. Local $ItemCount = _GUICtrlListView_GetItemCount($listview), $Checked[$ItemCount + 1] Local $X = 1 ; <<<<<<<<<<<<<< updated code For $i = 0 To $ItemCount - 1 ; check all items in the lv and see if any are checked off If _GUICtrlListView_GetItemChecked($listview, $i) Then $Checked[$X] = $i $X += 1 ;ConsoleWrite($Checked[$X]) EndIf Next ReDim $Checked[$X] $Checked[0] = $X - 1 If $Checked[0] > 0 Then For $rows = 0 To $Checked[0] if GUICtrlRead($Checked[$rows]) > 0 then ContinueLoop ConsoleWrite($Checked[$rows]) _GUICtrlListView_DeleteItem($listview,$Checked[$rows]) Next EndIf EndFunc What I can't understand is why it delete only 50% of the rows at a time per press of the button... -
_GUICtrlListView_DeleteItemsSelected w/ Checkboxes
timdecker replied to timdecker's topic in AutoIt General Help and Support
I did that.... Local $ItemCount = _GUICtrlListView_GetItemCount($listview), $Checked[$ItemCount + 1] Local $X = 1 ; <<<<<<<<<<<<<< updated code For $i = 0 To $ItemCount - 1 ; check all items in the lv and see if any are checked off If _GUICtrlListView_GetItemChecked($listview, $i) Then _GUICtrlListView_DeleteItem($listview,$i) EndIf Next EndFunc But if I have multiple things selected, I have to hit delete multiple times. Sometimes it deletes one item at a time, sometimes it deletes 3 items, then 2 items, then 4 items.... EDIT: What it seems to be doing, is only deleting 1/2 of it at a time. So if I select 12, it will delete 6, then 3, then 2, then the last 1. How do I get it to delete all 12? -
_GUICtrlListView_DeleteItemsSelected w/ Checkboxes
timdecker replied to timdecker's topic in AutoIt General Help and Support
Thanks, I am have problems understanding why I have to hit delete multiple times. What's wrong with my loop? -
_GUICtrlListView_DeleteItemsSelected w/ Checkboxes
timdecker replied to timdecker's topic in AutoIt General Help and Support
For my first question, I have this code: Local $ItemCount = _GUICtrlListView_GetItemCount($listview), $Checked[$ItemCount + 1] Local $X = 1 ; <<<<<<<<<<<<<< updated code For $i = 0 To $ItemCount - 1 ; check all items in the lv and see if any are checked off If _GUICtrlListView_GetItemChecked($listview, $i) Then _GUICtrlListView_DeleteItem($listview,$i) EndIf Next EndFunc It deletes what is selected, but only 1 at a time. So if I have 5 things selected, I have to hit delete multiple times. For question 2: I don't need it anymore, since I am using DeleteItem instead of DeleteItemSelected....but I would still like to fix my loop so I only have to press delete once instead of multiple times. -
_GUICtrlListView_DeleteItemsSelected($listview) works fine to delete items in my listeview if I am "selecting" them by clicking on their name.... What I would like to do, is delete items in my listview based off of what is "checked" and not "selected" in blue. Also, is there a way disable "selecting", so that only my checkboxes serve a purpose? Thanks, Tim
-
_GUICtrlListView_GetItemChecked - IF Statement
timdecker replied to timdecker's topic in AutoIt General Help and Support
That was it! Thank you so much BMNH! I am so sorry about the runnable-program part! I forgot I had It designated to my specific input box for my dummy programs I guess I should have disabled the part where it was checking to see if the other App was open as well =/. Also, thanks for cleaning up my Globals, adding the ReDim and making my _LVChkBx function cleaner. One day, this will be ready for lab.... Again, thank you! Kind regards, Tim -
_GUICtrlListView_GetItemChecked - IF Statement
timdecker replied to timdecker's topic in AutoIt General Help and Support
The snippet you provided works for the most part, it is just not keeping a count of the total number of items checked.... Here is the full code (your snippet is at lines 224 - 233): #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 $Form1 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) $Form1 = 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 $selectAll _LVChkBx(True, True) Case $clearAll _LVChkBx(False, True) 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 _LVChkBx($f_Check, $f_All) Local $hLV = ControlGetHandle($Form1, "", $ListView) Local $iCnt If $f_All Then _GUICtrlListView_SetItemChecked($hLV, -1, $f_Check) Else $iCnt = ControlListView($Form1, "", $hLV, "GetItemCount") For $n = 0 To $iCnt - 1 If ControlListView($Form1, "", $hLV, "IsSelected", $n) Then _GUICtrlListView_SetItemChecked($hLV, $n, $f_Check) Next EndIf EndFunc ;==>_LVChkBx 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) $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210,$iLVStyle,$iLVExtStyle) 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 Local $allRows = _GUICtrlListView_GetItemCount($listview) Local $iState = WinGetState($title_1) If BitAND($iState,1) <> 1 then MsgBox(0, "Application Not Open", "Make sure the instrument application" & @CRLF & "window is open...") Else Local $ItemCount = _GUICtrlListView_GetItemCount($ListView), $Checked[$ItemCount + 1] Local $X = 1 ; <<<<<<<<<<<<<< updated code For $I = 0 To $ItemCount - 1 ; check all items in the lv and see if any are checked off If _GUICtrlListView_GetItemChecked($ListView, $I) Then $Checked[$X] = $I ;consolewrite($checked[$X]) endif Next ReDim $Checked[$X] $Checked[0] = $X - 1 consolewrite($checked[0]) 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 _GUICtrlListView_GetItemChecked($listview, $rows) then 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 EndIf Next EndIf EndFunc Func cleanListview() GUICtrlDelete($listview) ;_GUICtrlListView_DeleteAllItems($listview) For $i = 1 To $iCount GUICtrlDelete($acheck[$i]) Next EndFunc Here is a csv: 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 Just to reiterate, I should know the total number of items that are checked, that way if "0" are checked, the run button should not function (or at least have a msgbox telling you to select some samples). Thanks again BMNH, Tim -
_GUICtrlListView_GetItemChecked - IF Statement
timdecker replied to timdecker's topic in AutoIt General Help and Support
Ok, so taking the snippet you have from post #7, how do I merge it with this" 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 _GUICtrlListView_GetItemChecked($listview, $rows) then 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 EndIf Next Would it replace the current For Loop (integrated with the other functions inside of the current For Loop)? Or is it a separate For Loop, that comes before the one I post above? EDIT: I tried changing the variable names to match my current For loop to ingrate it, and when I tried consolewrite($checked[0]) to see how many I had selected, it was "0". Also, when I tried to just straight copy and paste your snippet and place it BEFORE my current For loop, again....when I tried consolewrite($checked[0]) to see how many I had selected, it was "0". -
_GUICtrlListView_GetItemChecked - IF Statement
timdecker replied to timdecker's topic in AutoIt General Help and Support
I am working with what you posted, and through it before my other FOR loop (which is used to "ControlSetText"), but what is: "$Checked[$x]" Is that suppose to be $Checked[$I]? If it is, when I do a console write of $Checked[0] all I get back is 17, which I think is the total number of rows minus 1, regardless of how many I have checked. -
_GUICtrlListView_GetItemChecked - IF Statement
timdecker replied to timdecker's topic in AutoIt General Help and Support
All that does is exclude the first row when I am copying the array. -
_GUICtrlListView_GetItemChecked - IF Statement
timdecker replied to timdecker's topic in AutoIt General Help and Support
Building on this.... Every time in i use: ElseIf _GUICtrlListView_GetItemChecked($listview, $rows) == False then msgbox(0,"", "You have no more samples, or none are selected") exitloop It will only run as long as I have the first row selected. What should I have done to avoid mandating the first row be selected? Thanks! TIm -
_GUICtrlListView_GetItemChecked - IF Statement
timdecker replied to timdecker's topic in AutoIt General Help and Support
Thanks again Melba23! I had to place it around my other IF statments, but this is what I ended up with: If _GUICtrlListView_GetItemChecked($listview, $rows) then ;thanks to Melba23 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;thanks to Melba23 The comments "thanks to Melba23" is what I added to ensure it answered my question above. Tim -
The ability to controlsettext should be limited to those items that are checked inside of the listview. If they aren't checked, they don't get get sent.... only the ones that are checked get sent. Where/how do I incorporate that logic? I know I am suppose to use "_GUICtrlListView_GetItemChecked" (or at least I think I am), but all the variations of IF statements and locations that I have tried has me stumped. #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 $Form1 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) $Form1 = 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 $selectAll _LVChkBx(True, True) Case $clearAll _LVChkBx(False, True) 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 _LVChkBx($f_Check, $f_All) Local $hLV = ControlGetHandle($Form1, "", $ListView) Local $iCnt If $f_All Then _GUICtrlListView_SetItemChecked($hLV, -1, $f_Check) Else $iCnt = ControlListView($Form1, "", $hLV, "GetItemCount") For $n = 0 To $iCnt - 1 If ControlListView($Form1, "", $hLV, "IsSelected", $n) Then _GUICtrlListView_SetItemChecked($hLV, $n, $f_Check) Next EndIf EndFunc ;==>_LVChkBx 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) $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210,$iLVStyle,$iLVExtStyle) 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() GUICtrlDelete($listview) ;_GUICtrlListView_DeleteAllItems($listview) For $i = 1 To $iCount GUICtrlDelete($acheck[$i]) Next EndFunc Thanks, Tim
-
Problems Destroy GUI and Re-Create
timdecker replied to timdecker's topic in AutoIt General Help and Support
Thanks Melba23! I was using "_GUICtrlListView_DeleteAllItems" for some odd reason, and I am not sure why.... Either way, it works now. Tim