Parsing Clipboard... with a twist

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
CoolVibe
Posts: 7
Joined: 21 Jun 2019, 21:11

Parsing Clipboard... with a twist

21 Jun 2019, 21:42

I have a data set in Excel - two columns wide and variable number of rows. Once I copy that data set in Excel, need to have AHK to (in Citrix environment):
-If clipboard is empty, stop script and give message box "clipboard is empty"
-If clipboard is not empty, then
-paste contents of first cell from column A
-wait x period
-paste contents of first cell from column B
-wait x period
-hit Enter key 3 times with wait y between each
-repeat loop with next row until nothing left to paste
-display message box "Done"

Tried below as starting point, but could not get it to work as needed...

Code: Select all

F1::
Loop, parse, clipboard , `r%A_Tab%
{
send, %A_LoopField%
sleep, 1000
}
return
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: Parsing Clipboard... with a twist

21 Jun 2019, 23:12

Something like this?

Code: Select all

SendMode, Input

column_1 := [], column_2 := []

wait_x   := 300
wait_y   := 100

F1::
    Loop, Parse, Clipboard, `n, `r
    {
        row := StrSplit(A_LoopField, A_Tab)

        column_1.Push(row[1])
        column_2.Push(row[2])
    }
    
    ; removing last array element (usually empty)
    column_1.Pop(), column_2.Pop()

    Loop, % column_1.Length() {
        Send, % column_1[A_Index]
        Sleep, % wait_x
        Send, % column_2[A_Index]
        Sleep, % wait_x
    
        Loop, 3 {
            Send, {Enter}
            Sleep, % wait_y
        }
    }

    MsgBox, Done
Return
CoolVibe
Posts: 7
Joined: 21 Jun 2019, 21:11

Re: Parsing Clipboard... with a twist

22 Jun 2019, 09:07

Only the "Done" message box shows up, but no data is pasted
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: Parsing Clipboard... with a twist

22 Jun 2019, 09:19

Oh, i forget about that. Actually i copy the excel table and test it with Send command on notepad, not paste it.
CoolVibe
Posts: 7
Joined: 21 Jun 2019, 21:11

Re: Parsing Clipboard... with a twist

22 Jun 2019, 09:38

Nothing happens in Notepad either, only the Done message box shows up
Right now my source of data is actually Microsoft Works, not Excel
Should that make any difference?
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: Parsing Clipboard... with a twist

22 Jun 2019, 09:50

CoolVibe wrote:
22 Jun 2019, 09:38
Right now my source of data is actually Microsoft Works, not Excel
Should that make any difference?
I think it's okay, as long each line is separated by Tab.
btw, can you test it with excel to see if it works?
CoolVibe
Posts: 7
Joined: 21 Jun 2019, 21:11

Re: Parsing Clipboard... with a twist

22 Jun 2019, 10:07

Ridwan wrote:
CoolVibe wrote:
22 Jun 2019, 09:38
Right now my source of data is actually Microsoft Works, not Excel
Should that make any difference?
I think it's okay, as long each line is separated by Tab.
btw, can you test it with excel to see if it works?
Testing with Excel is a bit of a problem because, on my home PC I don't have Excel, but on my work PC I don't have AHK (yet)
So right now my only option is Microsoft Works, if you are saying it should not make any difference then I am wondering why is it not working
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: Parsing Clipboard... with a twist

22 Jun 2019, 10:36

CoolVibe wrote:
21 Jun 2019, 21:42

Code: Select all

F1::
Loop, parse, clipboard , `r%A_Tab%
{
send, %A_LoopField%
sleep, 1000
}
return
From your previous code, is `r%A_Tab% use as the line delimiter? Not `r`n?
CoolVibe
Posts: 7
Joined: 21 Jun 2019, 21:11

Re: Parsing Clipboard... with a twist

22 Jun 2019, 10:50

I am very new to AHK, and not sure how to answer that, except to say that my data set contains cells:
A1, B1
A2, B2
A3, B3
and so on...
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: Parsing Clipboard... with a twist

22 Jun 2019, 11:07

How about this?
I change the delimiter to `r%A_Tab% just like your previous code.

Code: Select all

SendMode, Input

wait_x   := 300
wait_y   := 100

F1::
    column_1 := [], column_2 := []
    
    Loop, Parse, Clipboard, `r%A_Tab%
    {
        row := StrSplit(A_LoopField, A_Tab)

        column_1.Push(row[1])
        column_2.Push(row[2])
    }
    
    ; removing last array element (usually empty)
    column_1.Pop(), column_2.Pop()

    Loop, % column_1.Length() {
        Send, % column_1[A_Index]
        Sleep, % wait_x
        Send, % column_2[A_Index]
        Sleep, % wait_x
    
        Loop, 3 {
            Send, {Enter}
            Sleep, % wait_y
        }
    }

    MsgBox, Done
Return
CoolVibe
Posts: 7
Joined: 21 Jun 2019, 21:11

Re: Parsing Clipboard... with a twist

22 Jun 2019, 11:38

Ridwan wrote:
22 Jun 2019, 11:07
How about this?
I change the delimiter to `r%A_Tab% just like your previous code.

Code: Select all

SendMode, Input

wait_x   := 300
wait_y   := 100

F1::
    column_1 := [], column_2 := []
    
    Loop, Parse, Clipboard, `r%A_Tab%
    {
        row := StrSplit(A_LoopField, A_Tab)

        column_1.Push(row[1])
        column_2.Push(row[2])
    }
    
    ; removing last array element (usually empty)
    column_1.Pop(), column_2.Pop()

    Loop, % column_1.Length() {
        Send, % column_1[A_Index]
        Sleep, % wait_x
        Send, % column_2[A_Index]
        Sleep, % wait_x
    
        Loop, 3 {
            Send, {Enter}
            Sleep, % wait_y
        }
    }

    MsgBox, Done
Return
This code is getting us closer to solution - it does paste/send (whichever is the proper term) the data, however after pasting from first column it hits Enter key 3 times, then after pasting from second column it hits Enter key 4 times for each row of data. Whereas what is needed - is to hit Enter key 3 times, but only after pasting from the second column for each row of data. Maybe that's why this is with a twist :)
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: Parsing Clipboard... with a twist

22 Jun 2019, 12:00

CoolVibe wrote:
22 Jun 2019, 11:38
This code is getting us closer to solution - it does paste/send (whichever is the proper term) the data, however after pasting from first column it hits Enter key 3 times, then after pasting from second column it hits Enter key 4 times for each row of data. Whereas what is needed - is to hit Enter key 3 times, but only after pasting from the second column for each row of data. Maybe that's why this is with a twist :)
Nice.., Maybe it's becase there is some different between Microsoft Works and Excel column and row structure, which make the program parsing it with incorrect delimiter.
It's seem to fix this bug, but with the file structure to experiment. :D
CoolVibe
Posts: 7
Joined: 21 Jun 2019, 21:11

Re: Parsing Clipboard... with a twist

22 Jun 2019, 12:12

Thank you so much for your input & troubleshooting, it's a good start
For now I think it will make sense to keep this question opened - maybe someone else has a solution and/or once my iT @ work installs AHK I will find solution through testing/experimenting and return here with a result :thumbup:
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: Parsing Clipboard... with a twist

22 Jun 2019, 12:42

Good, i will watch this topic. :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Google [Bot], Joey5, ShatterCoder, Xaucy and 188 guests