Sign in to follow this  
Followers 0
Blue_Drache

Retrieving from Clipboard

4 posts in this topic

Ok, the purpose of this code is to retrieve a document control number from any position on the screen within an AS/400 (or similar). Becasue AutoIt cannot read the screen directly, everything has to be manipulated within the Clipboard or create a temp file. I'm hoping to use the clipboard instead of creating temp files in the C:\Windows\temp.

The control number is always preceeded by the pattern "DCN: " which is why I use the "StringInStr" function. And I'm trying to retrieve the 12 digits after the pattern, hence the "StringLeft" function.

My problem is, that I can find the pattern "DCN: " just fine, but my msgbox is returning the POSITION of the pattern, and not the 12 digits after pattern, or even the pattern.

I know there's a flaw in the logic, but ..... I don't see it. I feel I'm in the right neighborhood, but knocking on the wrong house door. Can I get a cup of sugar anyway?

; Auto document number grabbing.

; declaration of functions and variables.

HotKeySet("{ESC}","MyExit")

DIM $test1 = -1, $test2 = -1, $dcn = -1, $yes = 6, $no = 7, $cancel = 2

; Start by putting the screen text in the clipboard.

WinActivate("A - [24 x 80]")
send("{altdown}EC{altup}"); Clears the screen of any selection boxes
send("{altdown}EA{altup}"); Selects the entire screen 24 rows x 80 coloumns
send("{altdown}EC{altup}"); Captures entrie screen to the clipboard.

; attempt to retrieve the document number from any location in the clipboard.

$dcn = StringLeft(StringInStr(ClipGet(),"DCN: "),12) ; this line is the headeache!!!!!

; print out the document number

MsgBox(48,"StringTest",$dcn)

; function list

Func MyExit()
    Exit 0
EndFunc

; end of file

Exit

Thanks in advance for your assistance.


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

Share this post


Link to post
Share on other sites



The control number is always preceeded by the pattern "DCN: " which is why I use the "StringInStr" function.  And I'm trying to retrieve the 12 digits after the pattern, hence the "StringLeft" function.

My problem is, that I can find the pattern "DCN: " just fine, but my msgbox is returning the POSITION of the pattern, and not the 12 digits after pattern, or even the pattern.

If you know the position, how about StringMid? to extract the number.

$number = StringInStr(ClipGet(),"DCN: ")

$answer = StringMid ( ClipGet(), $number, 12 )

Maybe a StringTrimLeft also to remove the DCN start?

Share this post


Link to post
Share on other sites

If you know the position, how about StringMid? to extract the number.

$number = StringInStr(ClipGet(),"DCN: ")

$answer = StringMid ( ClipGet(), $number, 12 )

Maybe a StringTrimLeft also to remove the DCN start?

<{POST_SNAPBACK}>

*slaps forehead*

And I blew right over that in the help file.

me = :idiot:


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

Share this post


Link to post
Share on other sites

Just for the log, here's your error:

$dcn = StringLeft(StringInStr(ClipGet(),"DCN: "),12); this line is the headeache!!!!!
StringInStr returns the position where the string can be found. So you're telling StringLeft to get the first twelve digits from the position and not from the string.

Correct would be:

$Clip=ClipGet()
$dcn=StringMid($Clip, StringInStr($Clip, "DCN: ") + 5, 12)
I didn't test it but it should give you an idea. I added +5 (the length of the "DCN: "-string) to the position because I guess you want $dcn to be "123456789012" and not "DCN: 123456789012".

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