Sign in to follow this  
Followers 0
timdecker

Loop through arrays to target input box and submit

35 posts in this topic

Goal: I have a csv file with 4 different columns. What I would like to be able to do is send these array values to an input box in a specified window. For testing purposes, I am only concerned about the columns labeled "material_name" and "letter". How do I go about sending value 1 from array["material_name"] to XY then sending value 1 from array["letter"] to a 2nd XY, and then click 2 buttons. Then I need to continue this trend ie... Send value 2 from array["material_name"] to XY then sending value 2 from array["letter"] to a 2nd XY, and then click 2 buttons...and so on an so forth until the end of the list.

For testing purposes I am using this website site for its input fields: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_legend

This is a pic showing the input fields in the order I wish for things to occur:

woN2YLb.png

Here is my current Code:

#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>

Global $a_csv


$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)
    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]
    ;consolewrite($iCount)


    ;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)

        ;ConsoleWrite($aCheck[1])
    Next

    For $i = 2 To UBound($a_csv) - 1
        $s_temp = StringReplace($a_csv[$i], ",", "|")
        GUICtrlCreateListViewItem($s_temp, $listview)
    Next


;~ #cs  -- Below

    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
;~ #ce -- See above


EndIf

GUISetState()
#cs - old while loop to change state of button, below
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            For $i = 1 To $iCount
                If $msg = $aCheck[$i] Then
                    If GUICtrlRead($msg) = 1 Then
                        GUICtrlSetState($mapColumn[$i], $GUI_ENABLE)
                    Else
                        GUICtrlSetState($mapColumn[$i], $GUI_DISABLE)
                    EndIf
                    ExitLoop

                EndIf
            Next
    EndSwitch
WEnd
#ce - old while loop to change state of button, above
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        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

Exit

And here is the csv file:

material_name,material_alias,period,letter
HT-000001331,,r1,A1
HT-000001330,alias 3 not 4,r2,A2
dummy,,,A3
RS-000001336,,r4,A4
HT-000001335,,r2,A5
dummy,,,A6
HT-000001334,,r2,A7
HT-000001328,alias1,r1,A8
HT-000001333,,r2,B1
dummy,,,B2
dummy,,,B3
HT-000001332,,r1,B4
dummy,,,B5
HT-000001332,,r2,B6
HT-000001329,alias 2,r2,B7
dummy,,,B8
dummy,,,C1
dummy,,,C2
HT-000001329,alias 2,r1,C3
HT-000001334,,r1,C4
RS-000001336,,r1,C5
dummy,,,C6
HT-000001333,,r1,C7
dummy,,,C8
dummy,,,D1
dummy,,,D2
dummy,,,D3
dummy,,,D4
RS-000001336,,r2,D5
dummy,,,D6
HT-000001330,alias 3 not 4,r1,D7
HT-000001331,,r2,D8
dummy,,,E1
dummy,,,E2
HT-000001335,,r1,E3
RS-000001336,,r3,E4
dummy,,,E5
RS-000001336,,r5,E6
HT-000001328,alias1,r2,E7
dummy,,,E8

You could probably ignore some of the code as I am no longer trying to manually map the XY each time the program is run and have decided just to go the hardcode XY path...

Thanks AUTOIT community!

Tim

Share this post


Link to post
Share on other sites



i can trow you only idea, cuz got not much time to build actual code

 

with _GUICtrlListView_GetItemCount get ure table size

 _GUICtrlListView_GetItem  (tableid, row, subitem(column) )  - get whats written in the cell

note -  _GUICtrlListView_GetItem  returns array, for text u need to read [3] - Item text

im just not sure, if u need to populate ure listview with _GUICtrlListView_AddItem and _GUICtrlListView_AddSubItem metods for this to work, but it would look something like this

$allrows = _GUICtrlListView_GetItemCount(table_id)

For $rows = 0 to $allrows -1  ;  (because this metod uses table 0 based)

   $material_name = _GUICtrlListView_GetItem(table_id, $rows, 0)

  $letter = _GUICtrlListView_GetItem(table_id, $rows, 3)

; put ure material name somewhere using $material_name[3]

; put ure letter using $letter[3]

; press buttons, do some loadwaits, continue

next

 

HTH

 

Share this post


Link to post
Share on other sites

i can trow you only idea, cuz got not much time to build actual code

 

with _GUICtrlListView_GetItemCount get ure table size

 _GUICtrlListView_GetItem  (tableid, row, subitem(column) )  - get whats written in the cell

note -  _GUICtrlListView_GetItem  returns array, for text u need to read [3] - Item text

im just not sure, if u need to populate ure listview with _GUICtrlListView_AddItem and _GUICtrlListView_AddSubItem metods for this to work, but it would look something like this

$allrows = _GUICtrlListView_GetItemCount(table_id)

For $rows = 0 to $allrows -1  ;  (because this metod uses table 0 based)

   $material_name = _GUICtrlListView_GetItem(table_id, $rows, 0)

  $letter = _GUICtrlListView_GetItem(table_id, $rows, 3)

; put ure material name somewhere using $material_name[3]

; put ure letter using $letter[3]

; press buttons, do some loadwaits, continue

next

 

HTH

So I added the follow:

$allRows =  _GUICtrlListView_GetItemCount($a_csv)
    For $rows = 0 to $allRows-1
        $material_name = _GUICtrlListView_GetItem($a_csv, $rows, 0)
        $letter = _GUICtrlListView_GetItem($a_csv, $rows, 3)
        ConsoleWrite($letter[1])
    Next

ConsoleWrite does not return anything....should it be returning position 1 for $letter?

Share this post


Link to post
Share on other sites

_GUICtrlListView_GetItem returns an array, so you will get nothing in your ConsoleWrite.


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

#5 ·  Posted (edited)

1 = based item image overlay index

try [3]

ConsoleWrite($letter[3])

 

Edited by Zobengrauzis

Share this post


Link to post
Share on other sites

_GUICtrlListView_GetItem returns an array, so you will get nothing in your ConsoleWrite.

 

So with the snippet of code I have above, how do I send it to a specified XY loc.?

1 = based item image overlay index

try [3]

ConsoleWrite($letter[3])

 

 

Look above, it wont work like that

Thanks BrewManHW and Zobengrauzis!

Tim

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

1. (sorry forgot you aint so familiar)

    #include <GuiListView.au3>
    #include <Array.au3>

2.

ConsoleWrite($letter[1])   - this is what you used

ConsoleWrite($letter[3])   - this is what i suggested

in ure case, you are not reading text of the cell, because if you look in help file in the function, you have

Return Value

Returns an array with the following format:
    [0] - Item state, which can be a combination of the following:
        1 - The item is marked for a cut-and-paste operation
        2 - The item is highlighted as a drag-and-drop target
        4 - The item has the focus
        8 - The item is selected
    [1] - 1-based item image overlay index
    [2] - 1-based item state image index
    [3] - Item text
    [4] - 0-based item image index
    [5] - Item application defined value
    [6] - Number of image widths to indent the item
    [7] - Identifier of the tile view group that receives the item

 

Edited by Zobengrauzis

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

1. #include <GuiListView.au3>

 

2.

ConsoleWrite($letter[1])   - this is what you used

ConsoleWrite($letter[3])   - this is what i suggested

in ure case, you are not reading text of the cell, because if you look in help file in the function, you have

Return Value

Returns an array with the following format:

    [0] - Item state, which can be a combination of the following:

        1 - The item is marked for a cut-and-paste operation

        2 - The item is highlighted as a drag-and-drop target

        4 - The item has the focus

        8 - The item is selected

    [1] - 1-based item image overlay index

    [2] - 1-based item state image index

    [3] - Item text

    [4] - 0-based item image index

    [5] - Item application defined value

    [6] - Number of image widths to indent the item

    [7] - Identifier of the tile view group that receives the item

 

It still does not return anything....

Snippet:

Edit: Changed $a_csv to $listview and it works.

;getItemCount
    ; _GUICtrlListView_GetItemCount(
    $allRows =  _GUICtrlListView_GetItemCount($a_csv)
    For $rows = 0 to $allRows-1
        $material_name = _GUICtrlListView_GetItem($a_csv, $rows, 0)
        $letter = _GUICtrlListView_GetItem($a_csv, $rows, 3)
        ; put ure material name somewhere using $material_name[3]
        ; put ure letter using $letter[3]
        ; press buttons, do some loadwaits, continue
        ConsoleWrite($letter[3])
    Next

Full Code:

Edit: #include <array.au3>

Ok, now that I can view it with consoleWrite, I need to be able to map it to XY for the loop.

#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


$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)
    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]
    ;consolewrite($iCount)



    ;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)

        ;ConsoleWrite($aCheck[1])
    Next

    For $i = 2 To UBound($a_csv) - 1
        $s_temp = StringReplace($a_csv[$i], ",", "|")
        GUICtrlCreateListViewItem($s_temp, $listview)
    Next

;getItemCount
    ; _GUICtrlListView_GetItemCount(
    $allRows =  _GUICtrlListView_GetItemCount($listview)
    For $rows = 0 to $allRows-1
        $material_name = _GUICtrlListView_GetItem($listview, $rows, 0)
        $letter = _GUICtrlListView_GetItem($listview, $rows, 3)
        ; put ure material name somewhere using $material_name[3]
        ; put ure letter using $letter[3]
        ; press buttons, do some loadwaits, continue
        ConsoleWrite($material_name[3])
    Next


;~ #cs  -- Below

    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
;~ #ce -- See above


EndIf

GUISetState()
#cs - old while loop to change state of button, below
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            For $i = 1 To $iCount
                If $msg = $aCheck[$i] Then
                    If GUICtrlRead($msg) = 1 Then
                        GUICtrlSetState($mapColumn[$i], $GUI_ENABLE)
                    Else
                        GUICtrlSetState($mapColumn[$i], $GUI_DISABLE)
                    EndIf
                    ExitLoop

                EndIf
            Next
    EndSwitch
WEnd
#ce - old while loop to change state of button, above
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        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

Exit
Edited by timdecker

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

ahh i see. put $listview in the $a_csv.

Edited by Zobengrauzis

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

ahh i see. put $listview in the $a_csv.

Yeah, I saw that to, stupid me =)

c/p wrong var.

So now that we have it loaded into an array....how do we go about sending it to a specified XY and clicking specified buttons?

Note: Line 1 of Array[1], then line 1 of array[2] --> button --> button --> Line 2 of Array[1], then line 2 of array[2] --> button --> button --> repeat until end of array

Thanks again Zobengrauzis!

Edited by timdecker

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

by XY you mean mouse coordinates on screen? does target is an input box control in some other application? can you specify? is it other kind of application? or internet explorer/other preffered explorer?

Edited by Zobengrauzis

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

by XY you mean mouse coordinates on screen? does target is an input box control in some other application? can you specify? is it other kind of application? or internet explorer/other preffered explorer?

I am trying to target the input box of another application...but I cannot justify testing it on the machine with said application until I can get it to work elsewhere.

So for now, I am using this website as an example: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_legend

For testing with the website, IE or chrome will work best.

And yes, XY, as in coordinates on the screen, until I can run autoInfo on the machine with the application it will be targeting in the end....

I hope that was enough insight... if not ask, and I will provide.

THANKS!!!!

Edited by timdecker

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

with applications (and if i presume you want the XY because target could move) i would suggest getting that input controls handle (autoit windows info - shows most of them, there is advabced one which can show almost any, but its more complicated than just getting from autoit windows info tool)  and then all you need to do is ControlSetText("title", "text", controlID, $letter[3]) for the input box and controlclick("title", "text", controlID) for the buttons. no matter where they are - no matter how many applications are popuped on them.

else you gotta code lotta mouse movements, lotta mouse clicks, lotta waits, lotta possible errors (because you cant check if that thing hasnt moved ir hasnt been brought bachground by some other application).

i strongly suggest you dont go this way. it is so error-possible, that is ridiculous.

Edited by Zobengrauzis

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

with applications (and if i presume you want the XY because target could move) i would suggest getting that input controls handle (autoit windows info - shows most of them, there is advabced one which can show almost any, but its more complicated than just getting from autoit windows info tool)  and then all you need to do is ControlSetText("title", "text", controlID, $letter[3]) for the input box and controlclick("title", "text", controlID) for the buttons. no matter where they are - no matter how many applications are popuped on them.

else you gotta code lotta mouse movements, lotta mouse clicks, lotta waits, lotta possible errors (because you cant check if that thing hasnt moved ir hasnt been brought bachground by some other application).

i strongly suggest you dont go this way. it is so error-possible, that is ridiculous.

Ok, so lets say we don't go about the XY (for now...). How would you go about this?

Using this site as a test case: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_legend

OR

Just use IE or chrome in general (using the search bar/box as input boxes and go/refresh as buttons)

 

Thanks!

Edited by timdecker

Share this post


Link to post
Share on other sites

for explorers its very different than for applications. explorers involve getting DOM objects of wanted controls and manipulating them after.

let me just give you example of how it would look if you got the control handles for your application.

    ; _GUICtrlListView_GetItemCount(
    $allRows =  _GUICtrlListView_GetItemCount($listview)
    For $rows = 0 to $allRows-1
        $material_name = _GUICtrlListView_GetItem($listview, $rows, 0)
        $letter = _GUICtrlListView_GetItem($listview, $rows, 3)
        controlsettext("Myapplication title", "", MY_HANDLE_INPUTBOX_1, $material_name[3])

        controlsettext("Myapplication title", "", MY_HANDLE_INPUTBOX_2, $letter[3])
        controlclick("Myapplication title", "", MY_HANDLE_BUTTON_1)

;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("Myapplication title", "", MY_HANDLE_BUTTON_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

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

for explorers its very different than for applications. explorers involve getting DOM objects of wanted controls and manipulating them after.

let me just give you example of how it would look if you got the control handles for your application.

    ; _GUICtrlListView_GetItemCount(

    $allRows =  _GUICtrlListView_GetItemCount($listview)

    For $rows = 0 to $allRows-1

        $material_name = _GUICtrlListView_GetItem($listview, $rows, 0)

        $letter = _GUICtrlListView_GetItem($listview, $rows, 3)

        controlsettext("Myapplication title", "", MY_HANDLE_INPUTBOX_1, $material_name[3])

        controlsettext("Myapplication title", "", MY_HANDLE_INPUTBOX_2, $letter[3])

        controlclick("Myapplication title", "", MY_HANDLE_BUTTON_1)

;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("Myapplication title", "", MY_HANDLE_BUTTON_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

Thanks! I am trying to find a dummy/test application that I can try this on.

Also, how do I only let this run when I click the "Go" button?

Edited by timdecker

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

put this loop into a separate function. and make the button run this function. (note - remember to put listview in global variables, so that the function can reach it)

you can play around with notebad, thou there is only 1 input box, and menuitems instead of buttons. well start with small, try to change that 1 input box in a loop :)

Edited by Zobengrauzis

Share this post


Link to post
Share on other sites

put this loop into a separate function. and make the button run this function. (note - remember to put listview in global variables, so that the function can reach it)

you can play around with notebad, thou there is only 1 input box, and menuitems instead of buttons. well start with small, try to change that 1 input box in a loop :)

 

Ok, so I have this function:

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", "", 0x00180E92, $material_name[3])

        controlsettext("HPOV", "", 0x001C0E62, $letter[3])
        controlclick("HPOV", "", 0x001E0E9E)

;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", "", 0x006B0D1A)

;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

And I have this button created and event to call the function:

GUICtrlCreateButton("Run Program", 700, 400, 180, 30)
    GUICtrlSetOnEvent(1, "copyToInput")

But it is not doing anything....

Entire Code:

#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


$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)
    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]
    ;consolewrite($iCount)



    ;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)
    GUICtrlCreateButton("Run Program", 700, 400, 180, 30)
    GUICtrlSetOnEvent(1, "copyToInput")
    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)

        ;ConsoleWrite($aCheck[1])
    Next

    For $i = 2 To UBound($a_csv) - 1
        $s_temp = StringReplace($a_csv[$i], ",", "|")
        GUICtrlCreateListViewItem($s_temp, $listview)
    Next

#cs; _GUICtrlListView_GetItemCount(
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", "", 0x00180E92, $material_name[3])

        controlsettext("HPOV", "", 0x001C0E62, $letter[3])
        controlclick("HPOV", "", 0x001E0E9E)

;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", "", 0x006B0D1A)

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



;~ #cs  -- Below

    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
;~ #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", "", 0x00180E92, $material_name[3])

        controlsettext("HPOV", "", 0x001C0E62, $letter[3])
        controlclick("HPOV", "", 0x001E0E9E)

;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", "", 0x006B0D1A)

;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


GUISetState()
#cs - old while loop to change state of button, below
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            For $i = 1 To $iCount
                If $msg = $aCheck[$i] Then
                    If GUICtrlRead($msg) = 1 Then
                        GUICtrlSetState($mapColumn[$i], $GUI_ENABLE)
                    Else
                        GUICtrlSetState($mapColumn[$i], $GUI_DISABLE)
                    EndIf
                    ExitLoop

                EndIf
            Next
    EndSwitch
WEnd
#ce - old while loop to change state of button, above
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        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

Exit

??????????????????

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

put all your gui building into function, and start scriot with calling this function. or else ure code will start to get really messy.

whats for setonevent - you havn't needed options for that to work. try and learn here: https://www.autoitscript.com/autoit3/docs/guiref/GUIRef_OnEventMode.htm

 

 

P.S. the less effort -

 Switch $msg
        Case $GUI_EVENT_CLOSE

        case $button ; (handle of this ->  GUICtrlCreateButton("Run Program", 700, 400, 180, 30))

           copyToInput()

 

 

 

and put the function to the very bottom

because everything, what is not in Func  /... /    end func    executes from top to buttom in the script.

Edited by Zobengrauzis

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

put all your gui building into function, and start scriot with calling this function. or else ure code will start to get really messy.

whats for setonevent - you havn't needed options for that to work. try and learn here: https://www.autoitscript.com/autoit3/docs/guiref/GUIRef_OnEventMode.htm

 

 

P.S. the less effort -

 Switch $msg

        Case $GUI_EVENT_CLOSE

        case $button ; (handle of this ->  GUICtrlCreateButton("Run Program", 700, 400, 180, 30))

           copyToInput()

 

 

 

and put the function to the very bottom

because everything, what is not in Func  /... /    end func    executes from top to buttom in the script.

 

I rearranged the code and created functions for my GUI; also, I added you above switch but it didn't do anything

The stupid :censored: code:

#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

$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


GUISetState()


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        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

 Switch $msg
        Case $GUI_EVENT_CLOSE

        case $runProg ; (handle of this ->  GUICtrlCreateButton("Run Program", 700, 400, 180, 30))



           copyToInput()
EndSwitch


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


EndFunc
Exit

One day...one day... :

Edited by timdecker

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
Sign in to follow this  
Followers 0