Sign in to follow this  
Followers 0
timdecker

Mapping X,Y and Copy/Pasting Array Values Until No More Samples

18 posts in this topic

Now that I have a somewhat decent UI going, I need help getting my buttons mapped and my data copy/pasted from the arrays to the input boxes. I have an image of the basic functionallity I would like, hopefully someone from this great community can help me finish this off.

qO0LwhF.png

#include <file.au3>
#include <GUIConstantsEx.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]

    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)
    ;$button_enabled = 1

    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

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)
                    Else
                        GUICtrlSetState($mapColumn[$i], $GUI_DISABLE)
                    EndIf
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd


Exit

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

If you need me to specify any more information, please ask and I will provide.

Thanks all!

Tim

Share this post


Link to post
Share on other sites



Is there a reason why you wouldn't just have one button to import all the data at once?

Assuming you need to update only certain columns, I think you will need to create an array and each time you need to update the listview, you will need to purge the data and re-paste it from the array. Also, you may want to consider using an INI file to store the data. I consider them pretty efficient unless you are dealing with a huge amount of data (maybe more than 1,000 entries), in which case you might want to consider switching to a real database like SQL.


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

Hi Tim,

Can you explain a little more about what you are trying to do.  I don't understand "map" in your context.  You refer to input boxes but I don't see any.  Lastly, you are acting on your data directly.  Where does "copy/paste" come in?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Is there a reason why you wouldn't just have one button to import all the data at once?

Assuming you need to update only certain columns, I think you will need to create an array and each time you need to update the listview, you will need to purge the data and re-paste it from the array. Also, you may want to consider using an INI file to store the data. I consider them pretty efficient unless you are dealing with a huge amount of data (maybe more than 1,000 entries), in which case you might want to consider switching to a real database like SQL.

I guess the data could be imported all at once. The CSV file generated from our SQL database. Each time we run an instrument, 40 samples are pulled from the DB by our LIMS-like interface. From there the CSV file is sent to the instrument PC, where I am trying to automate the naming of each sample file on the instrument. The instrument PC is on a different domain than the DB which is why we cannot pull from it directly. Any time we run an instrument, a new CSV file is generated and the old one is archived, so it is not a "live" update of the listview.

Hi Tim,

Can you explain a little more about what you are trying to do.  I don't understand "map" in your context.  You refer to input boxes but I don't see any.  Lastly, you are acting on your data directly.  Where does "copy/paste" come in?

kylomas

 

Above, I explained a little more about the purpose of this utility. What the "map" does is tell the program where the input field is for that specific column. The input boxes is from a piece of software that is used to run the instruments. The best way I can think to test this would be to use a browser; whereby, the address bar is an input box and possibly the searchbar is also an input box and the "Go" or "Refresh" button is the "sample submition button". After each time the "Go"/"Refresh" button is pushed it moves to the next line of samples and places the next values in the input box.

Example:

Address Bar: HT-0000213

Searchbar: R1

GO/Refresh

Next sample....

 

Address Bar: HT-0000214

Searchbar: R5

GO/Refresh

Next sample....until it has run through the entire array of samples.

I hope I was able to clear this up. If I am still unclear, or you need more information to help me make this come to fruition, please let me know.

Thanks,

Tim

Edited by timdecker

Share this post


Link to post
Share on other sites

what is the app your script is to work with?

It is to work with a piece of software from Metler to run our TGAs.

This is the software I am working with:

eiavZtb.png

But for testing purposes, my above post mentions using a web browser as it should sevrve just fine...

The more questions the better!

Thanks,

Tim

Share this post


Link to post
Share on other sites

woh........

 

Which is why I need to map the X,Y of the input box everytime we run new samples, someone is bound to move the damn screen and I doubt I will be able to get an ID (other than the window itself) for the input box. Once it is complete, I will search for a more robust way to handle the identity of the input box, but for now, the manual user defined x,y (by click in an area) will do just fine.

All help, comments, tips, and advice is appreaciated.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Which is why I need to map the X,Y of the input box everytime we run new samples, someone is bound to move the damn screen and I doubt I will be able to get an ID (other than the window itself) for the input box. Once it is complete, I will search for a more robust way to handle the identity of the input box, but for now, the manual user defined x,y (by click in an area) will do just fine.

All help, comments, tips, and advice is appreaciated.

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.  I did that when I was dealing with 5 different AS400 emulators, a web browser and two other page-displaying programs when I was automating medical insurance claim busywork.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

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.  I did that when I was dealing with 5 different AS400 emulators, a web browser and two other page-displaying programs when I was automating medical insurance claim busywork.

 

Ahhh, that makes sense! I will make a note of that in the code. What I am having trouble with right now, is creating arrays for each column. Since the number of columns is uknown, it needs to be thrown into a loop.

Coul you, or anyone else, look at my code above and help me with creating an array for each column:

ie:

$col -->

$col[1]            $col[2]             $col[3]

HT-00013                                   r2

HT-00014          alias1               r3

HT-00015

HT-00016          alias 3             r2

....

Share this post


Link to post
Share on other sites

#include <array.au3>
#include <file.au3>

Global $aArr

_FileReadToArray("new.csv" , $aArr)

Global $aOut[$aArr[0]][3]

for $i = 1 to $aArr[0]

    $aOut[$i - 1][0] = stringsplit($aArr[$i] , "," , 3)[0]
    $aOut[$i - 1][1] = stringsplit($aArr[$i] , "," , 3)[1]
    $aOut[$i - 1][2] = stringsplit($aArr[$i] , "," , 3)[2]

next

_ArrayDisplay($aOut)


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

#include <array.au3>
#include <file.au3>

Global $aArr

_FileReadToArray("new.csv" , $aArr)

Global $aOut[$aArr[0]][3]

for $i = 1 to $aArr[0]

    $aOut[$i - 1][0] = stringsplit($aArr[$i] , "," , 3)[0]
    $aOut[$i - 1][1] = stringsplit($aArr[$i] , "," , 3)[1]
    $aOut[$i - 1][2] = stringsplit($aArr[$i] , "," , 3)[2]

next

_ArrayDisplay($aOut)

I tried to use your code, and manipulate it such that it works with an unknown number of samples, but it didn't work for me.

Here is what I tried to replace it with, and I tried various other combinations. Could you or someone point out what is wrong?

Code I tried to use:

    Global $aOut[$a_csv[0]][$iCount]
    for $i = 1 to $a_csv[0]

    $aOut[$i - 1][1] = stringsplit($a_csv[$i] , "," , $iCount)[1]
    consolewrite($aOut[1][2])

    next

Full code, with the above commented out:

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


    ;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

#cs  -- Could Not Get to Work
    Global $aOut[$a_csv[0]][$iCount]
    for $i = 1 to $a_csv[0]

    $aOut[$i - 1][1] = stringsplit($a_csv[$i] , "," , $iCount)[1]
    consolewrite($aOut[1][2])

    next
#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)
                    Else
                        GUICtrlSetState($mapColumn[$i], $GUI_DISABLE)
                    EndIf
                    ExitLoop

                EndIf
            Next
    EndSwitch
WEnd



Exit

Thanks again guys!

Tim

Edited by timdecker

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

you have to redeclare dimensions

#include <array.au3>
#include <file.au3>

Global $aArr

_FileReadToArray("new.csv" , $aArr)

Global $aOut['']['']

for $i = 1 to $aArr[0]
    $aLine = stringsplit($aArr[$i] , "," , 3)
    If ubound($aLine) > ubound($aOut , 2) Then redim $aOut[$i][ubound($aLine)]
    _ArrayAdd($aOut , $aArr[$i] , 0 , ",")
next



_ArrayDisplay($aOut)
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

 

you have to redeclare dimensions

#include <array.au3>
#include <file.au3>

Global $aArr

_FileReadToArray("new.csv" , $aArr)

Global $aOut['']['']

for $i = 1 to $aArr[0]
    $aLine = stringsplit($aArr[$i] , "," , 3)
    If ubound($aLine) > ubound($aOut , 2) Then redim $aOut[$i][ubound($aLine)]
    _ArrayAdd($aOut , $aArr[$i] , 0 , ",")
next



_ArrayDisplay($aOut)

I am getting: "_ArrayAdd() called with the wrong number of args."

Edited by timdecker

Share this post


Link to post
Share on other sites

I'd guess your version is old, does the function in your include look like this?

https://www.autoitscript.com/autoit3/docs/libfunctions/_ArrayAdd.htm


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I'd guess your version is old, does the function in your include look like this?

https://www.autoitscript.com/autoit3/docs/libfunctions/_ArrayAdd.htm

Thanks boththose!

You were right, I had to download that function.

There is one more thing I would like to know....

If you use "consolewrite($aLine[1])" to help debug, it does not have each item return to a new line, nor does it include the "empty cells"; also, it includes the first line from the csv.

So, how do I get it to return the blank cells and seperate each value by a new line (or comma) so that I can get all the arrays to match up; also, to not include the first line from the csv?

Thanks!

Tim

EDIT:

Also, I think all I really needed was this:

#include <array.au3>
#include <file.au3>

Global $aArr

_FileReadToArray("ExperimentID_89.csv" , $aArr)

Global $aOut['']['']

for $i = 1 to $aArr[0]
    $aLine = stringsplit($aArr[$i] , "," , 3)
    consolewrite($aLine[1])
next

But my questions above still apply....

Edited by timdecker

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

If they are blanks, how would you know if they were not there?  pardon my sarcasm, they are in that string, they are just blank.

And you want line feeds in your consolewrite?  So put line feeds in your consolewrite.

#include <array.au3>
#include <file.au3>

Global $aArr

_FileReadToArray("ExperimentID_89.csv" , $aArr)

Global $aOut['']['']

for $i = 1 to $aArr[0]
    $aLine = stringsplit($aArr[$i] , "," , 3)
    consolewrite($aLine[1] & @LF)
next
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

 

If they are blanks, how would you know if they were not there?  pardon my sarcasm, they are in that string, they are just blank.

And you want line feeds in your consolewrite?  So put line feeds in your consolewrite.

#include <array.au3>
#include <file.au3>

Global $aArr

_FileReadToArray("ExperimentID_89.csv" , $aArr)

Global $aOut['']['']

for $i = 1 to $aArr[0]
    $aLine = stringsplit($aArr[$i] , "," , 3)
    consolewrite($aLine[1] & @LF)
next

 

Haha, so simple. And you sarcasm is much appreciated :thumbsup:

So now that I have my columns bound to an array, how do I think that array into my checkboxes; so that I can say, these are the columns (arrays) that I want to copy one at a time jumping from column to column and circling back around to the first column for the next line?

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