Jump to content

Loop through arrays to target input box and submit


Go to solution Solved by Zobengrauzis,

Recommended Posts

  • Solution

put the
While 1 loop inside gui building function

#cs
Solution to that is to move the window to the same screen location every time the program is run or the loop recycles.
Or test to see if it's on the X/Y you want and if not, force it there.


Use this as example for input box field when testing submition: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_legend
#ce

#include <file.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <Array.au3>


Global $a_csv
Global $listview
Global $checkboxName
Global $iCount
Global $runProg
Global $acheck
Global $mapColumn
global $runProg 

$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()


;~ #ce -- See above


EndIf



Func copyToInput()
    $allRows =  _GUICtrlListView_GetItemCount($listview)
    For $rows = 0 to $allRows-1
        $material_name = _GUICtrlListView_GetItem($listview, $rows, 0)
        $letter = _GUICtrlListView_GetItem($listview, $rows, 3)
        controlsettext("HPOV", "", 4, $material_name[3])
        controlsettext("HPOV", "", 5, $letter[3])
        controlclick("HPOV", "", 6)

        ;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
        controlclick("Job", "", 2)

        ;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
    Next
EndFunc

Func buildGUI()
    GUICreate("CSV Listview", 900, 450, -1, -1)
    $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 600, 210)
    $checkboxName = StringSplit($a_csv[1], ",")
    $iCount = $checkboxName[0]

    ;creating buttons
    Global $aCheck[$iCount + 1]
    Global $mapColumn[$iCount + 1]
    $nextSample = GUICtrlCreateButton("Map sample submition button ", 395, 320, 180, 30)
    $runProg = GUICtrlCreateButton("Run Program", 700, 400, 180, 30)

     For $j = 1 To $iCount
        ; Store controIDs of the checkboxes
        $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30)
        $mapColumn[$j] = GUICtrlCreateButton("Map " & '"'  & $checkboxName[$j] & '"' & " to input box", 150, 190 + (50 * $j), 180, 30)
        GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED)
        GUICtrlSetState($mapColumn[$j], $GUI_DISABLE)
    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 , ",")
            ;consolewrite("line: "  & $aLine[2] & @LF)
    Next



GUISetState()


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        
        case $runProg
            copyToInput()
        
        Case Else
            For $i = 1 To $iCount
                If $msg = $aCheck[$i] Then
                    If GUICtrlRead($msg) = 1 Then
                        GUICtrlSetState($mapColumn[$i], $GUI_ENABLE)
                        Local $text = ""
                        For $k = 0 to $a_csv[0]-1
                          $text &= ControlListView ("CSV Listview", "", $listview, "GetText", $k, $i-1) & @crlf

                        Next
                        Msgbox(0,$checkboxName[$i], $text) ; debug, can see the list of samples you selected
                    Else
                        GUICtrlSetState($mapColumn[$i], $GUI_DISABLE)
                    EndIf
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd






EndFunc
Edited by Zobengrauzis
Link to comment
Share on other sites

 

put the

While 1 loop inside gui building function

#cs
Solution to that is to move the window to the same screen location every time the program is run or the loop recycles.
Or test to see if it's on the X/Y you want and if not, force it there.


Use this as example for input box field when testing submition: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_legend
#ce

#include <file.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <Array.au3>


Global $a_csv
Global $listview
Global $checkboxName
Global $iCount
Global $runProg
Global $acheck
Global $mapColumn
global $runProg 

$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()


;~ #ce -- See above


EndIf



Func copyToInput()
    $allRows =  _GUICtrlListView_GetItemCount($listview)
    For $rows = 0 to $allRows-1
        $material_name = _GUICtrlListView_GetItem($listview, $rows, 0)
        $letter = _GUICtrlListView_GetItem($listview, $rows, 3)
        controlsettext("HPOV", "", 4, $material_name[3])
        controlsettext("HPOV", "", 5, $letter[3])
        controlclick("HPOV", "", 6)

        ;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
        controlclick("Job", "", 2)

        ;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
    Next
EndFunc

Func buildGUI()
    GUICreate("CSV Listview", 900, 450, -1, -1)
    $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 600, 210)
    $checkboxName = StringSplit($a_csv[1], ",")
    $iCount = $checkboxName[0]

    ;creating buttons
    Global $aCheck[$iCount + 1]
    Global $mapColumn[$iCount + 1]
    $nextSample = GUICtrlCreateButton("Map sample submition button ", 395, 320, 180, 30)
    $runProg = GUICtrlCreateButton("Run Program", 700, 400, 180, 30)

     For $j = 1 To $iCount
        ; Store controIDs of the checkboxes
        $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30)
        $mapColumn[$j] = GUICtrlCreateButton("Map " & '"'  & $checkboxName[$j] & '"' & " to input box", 150, 190 + (50 * $j), 180, 30)
        GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED)
        GUICtrlSetState($mapColumn[$j], $GUI_DISABLE)
    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 , ",")
            ;consolewrite("line: "  & $aLine[2] & @LF)
    Next



GUISetState()


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        
        case $runProg
            copyToInput()
        
        Case Else
            For $i = 1 To $iCount
                If $msg = $aCheck[$i] Then
                    If GUICtrlRead($msg) = 1 Then
                        GUICtrlSetState($mapColumn[$i], $GUI_ENABLE)
                        Local $text = ""
                        For $k = 0 to $a_csv[0]-1
                          $text &= ControlListView ("CSV Listview", "", $listview, "GetText", $k, $i-1) & @crlf

                        Next
                        Msgbox(0,$checkboxName[$i], $text) ; debug, can see the list of samples you selected
                    Else
                        GUICtrlSetState($mapColumn[$i], $GUI_DISABLE)
                    EndIf
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd






EndFunc

HOLY CRAP!

It works!

Thank you so much Zobengrauzis! I very much appreciate you sticking around! Now time to take it to the machine when it is done with the samples tomorrow.

THANKS AGAIN!

Tim

Link to comment
Share on other sites

Good luck then conquering that app!

Cya :bye:

 One more thing if you have a minute....How/where do I place an If statement to only place into the input box if the checkbox is checked....? I placed the if statement inside coptToInput function, but it continues to run the program (not copying, just clicking) if nothing is selected...

Edited by timdecker
Link to comment
Share on other sites

anywhere. just make sure it is only one and in the middle of If....  endif.  else it could execute without you wanting it

for....

code

code

   if checkbox=is checked then

     Put statement in box

  endif

 code

code

next

 

if there are thing which can make the whole current loop do nothing, you can make a check for this condition at start of a loop something like this", and it will jump right to the next loop, without checking other things in this current loop section  (to avoid deep IF corridors)

for

 if case_applie_nothing_need_to_be_done then continueloop

   code

   code

   code

next

 

exitloop - make the current loop exit right now, but continue running script/continued code after the loop (like if you want to to do loop till meeting some criteria and then stop without wasting time in left loop count)

Edited by Zobengrauzis
Link to comment
Share on other sites

for....

code

code

   if checkbox=is checked then

     Put statement in box

  endif

 code

code

next

 

if there are thing which makes the whole 1 loop do nothing, you can make at start of a loop something like this

for

 if case_applie_nothing_need_to_be_done then continueloop

   code

   code

   code

next

 

This works fine, as it will not use it if it is not checked:

If GUICtrlRead($aCheck[1]) = 1 Then
        controlsettext("HPOV", "", 4, $material_name[3])
        endif
        If GUICtrlRead($aCheck[4]) = 1 Then
        controlsettext("HPOV", "", 5, $letter[3])
        endif

However, it will still run the program and do nothing but click "ok".

I need to place in something in here by the case $runProg

While 1
            $msg = GUIGetMsg()
            Switch $msg
                Case $GUI_EVENT_CLOSE
                    ExitLoop

                case  $runProg
                    copyToInput()
;where to place the do nothing????
Edited by timdecker
Link to comment
Share on other sites

give me an example what looks liek the cases you would want to skip button pressing

if you want to skip button pressing, if any of them are uncheked, then

my guess:

If GUICtrlRead($aCheck[1]) <> 1 or GUICtrlRead($aCheck[4]) <> 1 then continueloop
        If GUICtrlRead($aCheck[1]) = 1 Then
        controlsettext("HPOV", "", 4, $material_name[3])
        endif
        If GUICtrlRead($aCheck[4]) = 1 Then
        controlsettext("HPOV", "", 5, $letter[3])
        endif
Edited by Zobengrauzis
Link to comment
Share on other sites

give me an example what looks liek the cases you would want to skip button pressing

 

I almost have it working, but I think I have a thing or 2 out of order or a syntax issue.

Here is a snippet of the while loop:

While 1
            $msg = GUIGetMsg()
            Switch $msg
                Case $GUI_EVENT_CLOSE
                    ExitLoop
                Case $GUI_EVENT_CLOSE
                    For $i = 1 To $iCount
                        If $msg = $aCheck[$i] Then
                            If GUICtrlRead($msg) = 1 Then
                            EndIf
                        EndIf
                        next
                                ExitLoop
                Case $runProg
                    copyToInput()
Link to comment
Share on other sites

While 1
            $msg = GUIGetMsg()
            Switch $msg
                Case $GUI_EVENT_CLOSE
                    ExitLoop
                
                Case $runProg
                    copyToInput()
              Case else
                    For $i = 1 To $iCount
                        If $msg = $aCheck[$i] Then
                            If GUICtrlRead($msg) = 1 Then
                            EndIf
                        EndIf
                        next

Link to comment
Share on other sites

While 1
            $msg = GUIGetMsg()
            Switch $msg
                Case $GUI_EVENT_CLOSE
                    ExitLoop
                
                Case $runProg
                    copyToInput()
              Case else
                    For $i = 1 To $iCount
                        If $msg = $aCheck[$i] Then
                            If GUICtrlRead($msg) = 1 Then
                            EndIf
                        EndIf
                        next

 

I think the above statement worked out fine: If GUICtrlRead($aCheck[1]) <> 1 or GUICtrlRead($aCheck[4]) <> 1 then continueloop

However, what I have quoted above...not so much.

Here is the full while statement with what you have above:

While 1
            $msg = GUIGetMsg()
            Switch $msg
                Case $GUI_EVENT_CLOSE
                    ExitLoop

                Case $runProg
                    copyToInput()

                Case else
                    For $i = 1 To $iCount
                        If $msg = $aCheck[$i] Then
                            If GUICtrlRead($msg) = 1 Then
                            EndIf
                        EndIf
                        next

                Case Else
                    For $i = 1 To $iCount
                        If $msg = $aCheck[$i] Then
                            If GUICtrlRead($msg) = 1 Then
                                GUICtrlSetState($mapColumn[$i], $GUI_ENABLE)
                                Local $text = ""
                                For $k = 0 to $a_csv[0]-1
                                  $text &= ControlListView ("CSV Listview", "", $listview, "GetText", $k, $i-1) & @crlf

                                Next
                                ;Msgbox(0,$checkboxName[$i], $text) ; debug, can see the list of samples you selected
                            Else
                                GUICtrlSetState($mapColumn[$i], $GUI_DISABLE)
                            EndIf
                            ExitLoop
                        EndIf
                    Next
            EndSwitch
    WEnd
Link to comment
Share on other sites

i said it was my guess. you didnt specify what is the condition. if u want to run with 1 or both of them checked,only skip if both are unchecked, then change OR to AND

Ahh stupid me! I thought I did change it to AND. Thanks for sticking in there Zobengrauzis!

I will test it in the lab tomorrow and let you know how it goes.

THANKS AGAIN!

Tim

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...