timdecker

_GUICtrlListView_GetItemChecked - IF Statement

15 posts in this topic

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

Share this post


Link to post
Share on other sites



timdecker,

It is a bit difficult to test without the GUI into which you are sending the text, but this seems to work in my heavily modified version of the script:

If _GUICtrlListView_GetItemChecked($listview, $rows) Then
    controlsettext($title_1, "", $textPos_1, $material_name[3])
EndIf
M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

timdecker,

It is a bit difficult to test without the GUI into which you are sending the text, but this seems to work in my heavily modified version of the script:

If _GUICtrlListView_GetItemChecked($listview, $rows) Then
    controlsettext($title_1, "", $textPos_1, $material_name[3])
EndIf
M23

 

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

What should I have done to avoid mandating the first row be selected?

Set $rows to something other than 0?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Set $rows to something other than 0?

 

All that does is exclude the first row when I am copying the array.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Loop through your array to see if any of the indices are selected and run an action accordingly.

Local $ItemCount = _GUICtrlListView_GetItemCount($hListView), $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($hListView, $I) Then
        $Checked[$X] = $I
Next
ReDim $Checked[$X]
$Checked[0] = $X - 1

This snippet will get the total number of items in the listview, then it will loop through the listview to see which ones have been checked, and stores the index of any checked items in the $Checked array, and it also stores the number of items that it found that were checked in $Checked[0].

Then you can loop through the $Checked array to do whatever it is that you need to do with the checked items in your listview. This will process a very large listview in well under a second.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Loop through your array to see if any of the indices are selected and run an action accordingly.

Local $ItemCount = _GUICtrlListView_GetItemCount($hListView), $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($hListView, $I) Then
        $Checked[$X] = $I
Next
ReDim $Checked[$X]
$Checked[0] = $X - 1

This snippet will get the total number of items in the listview, then it will loop through the listview to see which ones have been checked, and stores the index of any checked items in the $Checked array, and it also stores the number of items that it found that were checked in $Checked[0].

Then you can loop through the $Checked array to do whatever it is that you need to do with the checked items in your listview. This will process a very large listview in well under a second.

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.

Edited by timdecker

Share this post


Link to post
Share on other sites

I updated the code in post #7, I forgot to initialize the $X variable (cut and paste error). BTW, it's supposed to be $Checked[$x], and not $I.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I updated the code in post #7, I forgot to initialize the $X variable (cut and paste error). BTW, it's supposed to be $Checked[$x], and not $I.

 

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".

Edited by timdecker

Share this post


Link to post
Share on other sites

Give me something that I can run, that works the same way as your script does, and that doesn't look like a cat walked over the keyboard while typing it, and I can give you more help.

I'm not willing to try and create a fully working GUI with a listview just so you can find out how to do something so basic, and then I'll end up finding out you did it a completely different way than I came up with and we'll just have to go through it all over again.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Give me something that I can run, that works the same way as your script does, and that doesn't look like a cat walked over the keyboard while typing it, and I can give you more help.

I'm not willing to try and create a fully working GUI with a listview just so you can find out how to do something so basic, and then I'll end up finding out you did it a completely different way than I came up with and we'll just have to go through it all over again.

 

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

Share this post


Link to post
Share on other sites

I THINK I have what you need in this code.

#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[0]
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
    ReDim $acheck[$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   ;==>buildGUI

Func _LVChkBx($f_Check, $f_All)

    If $f_All Then
        _GUICtrlListView_SetItemChecked($listview, -1, $f_Check)
    Else
        _GUICtrlListView_SetItemChecked($listview, -1, $f_Check)
    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   ;==>_loadNewFile


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
                $X += 1
            EndIf
        Next
        ReDim $Checked[$X]
        $Checked[0] = $X - 1
        If $Checked[0] > 0 Then
            For $rows = 1 To $Checked[0]
                $material_name = _GUICtrlListView_GetItem($listview, $Checked[$rows], 0)
                $letter = _GUICtrlListView_GetItem($listview, $Checked[$rows], 3)

                If GUICtrlRead($acheck[1]) <> 1 And GUICtrlRead($acheck[4]) <> 1 Then ContinueLoop

                ControlSetText($title_1, "", $textPos_1, $material_name[3])

                #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
        Else
            ; Put your code here in case nothing was checked in the listview
        EndIf
    EndIf
EndFunc   ;==>copyToInput


Func cleanListview()
    GUICtrlDelete($listview)
    ;_GUICtrlListView_DeleteAllItems($listview)
    For $i = 1 To $iCount
        GUICtrlDelete($acheck[$i])
    Next
EndFunc   ;==>cleanListview

I've attempted to clean up some of the code, got rid of a couple of Global variables you declared inside functions that should have been declared as Local. Rewrote the Check/Uncheck all function, to make it work without redundant unnecessary code.

BTW, when asked to post runnable code, that usually means code that someone can run without needing to have the programs running that you need to run it on your computer.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I THINK I have what you need in this code.

#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[0]
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
    ReDim $acheck[$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   ;==>buildGUI

Func _LVChkBx($f_Check, $f_All)

    If $f_All Then
        _GUICtrlListView_SetItemChecked($listview, -1, $f_Check)
    Else
        _GUICtrlListView_SetItemChecked($listview, -1, $f_Check)
    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   ;==>_loadNewFile


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
                $X += 1
            EndIf
        Next
        ReDim $Checked[$X]
        $Checked[0] = $X - 1
        If $Checked[0] > 0 Then
            For $rows = 1 To $Checked[0]
                $material_name = _GUICtrlListView_GetItem($listview, $Checked[$rows], 0)
                $letter = _GUICtrlListView_GetItem($listview, $Checked[$rows], 3)

                If GUICtrlRead($acheck[1]) <> 1 And GUICtrlRead($acheck[4]) <> 1 Then ContinueLoop

                ControlSetText($title_1, "", $textPos_1, $material_name[3])

                #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
        Else
            ; Put your code here in case nothing was checked in the listview
        EndIf
    EndIf
EndFunc   ;==>copyToInput


Func cleanListview()
    GUICtrlDelete($listview)
    ;_GUICtrlListView_DeleteAllItems($listview)
    For $i = 1 To $iCount
        GUICtrlDelete($acheck[$i])
    Next
EndFunc   ;==>cleanListview

I've attempted to clean up some of the code, got rid of a couple of Global variables you declared inside functions that should have been declared as Local. Rewrote the Check/Uncheck all function, to make it work without redundant unnecessary code.

BTW, when asked to post runnable code, that usually means code that someone can run without needing to have the programs running that you need to run it on your computer.

 

 

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 :sweating:  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

Edited by timdecker

Share this post


Link to post
Share on other sites

:dance: I'm glad we got this working. :dance:


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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