Jump to content


Photo

Grab each line


  • Please log in to reply
28 replies to this topic

#1 SilverFish

SilverFish
  • Members
  • 105 posts

Posted 18 August 2012 - 12:58 PM

Trying to grab each line of the clipboard. Instead of a loop, I need to grab a single line separately. Exampe: MsgBox %line27%, MsgBox %line 34% Any ideas?

#2 toralf

toralf
  • Fellows
  • 3948 posts

Posted 18 August 2012 - 01:01 PM

Use stringsplit to separate the text

#3 SilverFish

SilverFish
  • Members
  • 105 posts

Posted 18 August 2012 - 01:52 PM

I've looked at the docs for that. Either I haven't figured it out or it doesn't seem possible. Can you give an example of deleting the first 15 lines?

#4 toralf

toralf
  • Fellows
  • 3948 posts

Posted 18 August 2012 - 02:28 PM

Please post your code that you have right now. Or maybe a small example that shows your case.

#5 SilverFish

SilverFish
  • Members
  • 105 posts

Posted 18 August 2012 - 05:40 PM

I am trying to find a way to do this, so no code yet. The clipboard is literally lines of text and I need to find a way to grab just one line.

#6 girlgamer

girlgamer
  • Moderators
  • 2039 posts

Posted 18 August 2012 - 06:39 PM

each line in the clipboard is terminated with a carriage-return linefeed pair. If that helps any

#7 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 18 August 2012 - 06:54 PM

Hi SilverFish,
Included with installation of AHk is a helpfile. The helpfile is mirrored on the AHk website.
Depending on the version you have installed it is at a different places
Ahk_basic <!-- m -->http://www.autohotkey.com/docs/<!-- m -->
AHK_L <!-- m -->http://l.autohotkey.net/docs/<!-- m -->

Within those docs is a command list, and withing that list is ClipWait <!-- m -->http://www.autohotke...ds/ClipWait.htm<!-- m -->
On the ClipWait page is a hyperlink to lots of info on using the clipboard,
"...clipboard contains data." <!-- m -->http://www.autohotke...c/Clipboard.htm<!-- m -->

The first example shows how to >parse< the clipboard.
btw, in computer terminology >parse< means to "cut into pieces."

#8 SilverFish

SilverFish
  • Members
  • 105 posts

Posted 18 August 2012 - 10:02 PM

This is what I've got so far and it seems to be giving me a set number of characters instead of the entire line.

StringSplit, outputarray, clipboard, ``n
MsgBox %outputarray23% ; line 23

What am I doing wrong here?

#9 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 18 August 2012 - 10:13 PM

You only need one back-tick
StringSplit, outputarray, clipboard, `n
MsgBox %outputarray23% ; line 23


#10 SilverFish

SilverFish
  • Members
  • 105 posts

Posted 18 August 2012 - 11:47 PM

whew! Got that working. It seems to work perfectly fine with a MsgBox, but I get the entire contents of the clipboard with Excel. :(
StringSplit, outputarray, clipboard, `n
;MsgBox %outputarray23% ; line 23

SendInput %date%
Sleep 200
SendInput {Tab}
Sleep 200
SendInput %outputarray23% ; Orders-Product Charges


#11 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 19 August 2012 - 12:18 AM

I have excel 2007, I put the following script in an autohotkey file. I saved and ran the script.
Btw, the lines between /* and */ are ignored by AHk.
With notepad open I selected and the array of numbers, and copied the slection with ^c.

I opened a blank workbook in excel and selected a cell.
When I hit F1, the selected cell moved 1 to the right and then "23" was entered into that new cell.

It appears that somewhere in the process, a tab character is picked-up and that causes the tab to the adjacent cell.

Try this script and report back. Please follow my steps as closely as possible and be as specific as possible in your report.

/*

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

*/

return

f1::

StringSplit, outputarray, clipboard, `n
;MsgBox %outputarray23% ; line 23

SendInput %date%
Sleep 200
SendInput {Tab}
Sleep 200
SendInput %outputarray23% ; Orders-Product Charges


return


#12 SilverFish

SilverFish
  • Members
  • 105 posts

Posted 19 August 2012 - 12:03 PM

It appears that the pieces you added are the two "return"s? If that was the case, I tried that and got the same results. :/ If there is a tab thrown in there, that would be great if I could see that "`n`r"s and any tab or other keys that are in there. Is there a text editor that shows that?

Also, could I do a StringReplace on all the tab keys and convert them to spaces?

Thanks!

#13 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 19 August 2012 - 01:53 PM

You do not follow instructions very well. :(

You previous post said that you got the "entire contents of the clipboard wirh excel."

I asked you to do precise steps (in order to diagnose your problem.)

AFAIK, You failed to do any of those steps and instead you theorized on what my results were.

#14 SilverFish

SilverFish
  • Members
  • 105 posts

Posted 19 August 2012 - 05:01 PM

You did not have any steps in your post. You said what you tried and the code you used. The only thing that I could see that you added are the two 'returns'. I guess I'm missing something from your post?

#15 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 20 August 2012 - 02:34 AM

It seems to work perfectly fine with a MsgBox, but I get the entire contents of the clipboard with Excel.

You listed your results, which were contrary to what should have been expected.
The expected results should have been the same for msgbox and sendinput.

Therefore, I laid out the steps I used to test your script.

And I wrote:

"...Try this script and report back. Please follow my steps..."

The purpose of the steps is to provide a 'baseline' so that we are using the same info.

If you want help from me, follow through with my request.