AutoHotkey Community

It is currently May 27th, 2012, 8:22 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: February 1st, 2012, 9:25 pm 
Offline

Joined: November 20th, 2010, 6:58 am
Posts: 76
Location: Tennessee
I currently have a macro that selects data from a system in order to determine if the value recorded matches any of the lines of data captured but it will not find a match and through testing I determined that because there are leading blanks (number of blanks depend on length of number) it is not finding the match. Here is what I have so far.

Code:
LoopParse:
Send, {SHIFTDOWN}{RIGHT 11}{DOWN 9}{SHIFTUP}
Sleep 300
Send ^c
ClipWait
Sleep 300

Loop, parse, clipboard, `r`n, , All
{
If A_LoopField = %PmtAmt%
{
LineNumber = %A_Index%
Sleep 200
Send {DOWN %LINENUMBER%}{UP}
GoTo MatchCheck#
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 1st, 2012, 9:35 pm 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
Use Trim() or OmitChars parameter in Parsing loop. Example:
Code:
Loop, Parse, Clipboard, `n, `r%A_Space%%A_Tab%


Last edited by Learning one on February 1st, 2012, 9:41 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 1st, 2012, 9:38 pm 
Offline

Joined: July 20th, 2009, 6:01 am
Posts: 166
Location: Amsterdam
By blanks, do you mean spaces? You could add a Regexreplace to your loop to remove all spaces at the beginning:

Code:
A_Loopfield := Regexreplace(A_Loopfield, "^\s+", "")  ; replaces all leading spaces in A_Loopfield by nothingness


If you add this above your If statement, initial spaces should be cleared before the loopfield is evaluated by If.

As an alternative, you could add an InStr to your If statement:

Code:
If InStr(A_Loopfield, PmtAmt)  ; If A_Loopfield contains the exact contents of the variable PmtAmt


Then, if PmtAmt is blurb, and A_Loopfield is " spacespaceblurbblahblah", If is true. InStr is faster than Regexmatch, so says the AHK help file.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 1st, 2012, 9:46 pm 
Cerberus wrote:
By blanks, do you mean spaces? You could add a Regexreplace to your loop to remove all spaces at the beginning
There is a built-in command for that which is probably faster http://l.autohotkey.net/docs/commands/Trim.htm (and easier)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 1st, 2012, 9:53 pm 
Offline

Joined: July 20th, 2009, 6:01 am
Posts: 166
Location: Amsterdam
Anonymous wrote:
Cerberus wrote:
By blanks, do you mean spaces? You could add a Regexreplace to your loop to remove all spaces at the beginning
There is a built-in command for that which is probably faster http://l.autohotkey.net/docs/commands/Trim.htm (and easier)
Ah! But I'm on AHK basic (scared that my scripts might break if I switch). So is everybody using AHK_L now? Or AHK2, even?—how is that taking off?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 1st, 2012, 10:05 pm 
Re: basic v _l: There are various threads discussing this, but in general if your scripts don't use DLLCalls, or the basic COM you shouldn't have a problem upgrading. You can simply download the ZIP version http://l.autohotkey.net/ (scroll to DOWNLOAD, not click it at the top) I suggest the Unicode x86 version, but you could try the Ansi also which is just like basic with the new features added. If you try the unicode be sure to save your scripts as UTF-8 as that is a common mistake. You can try your scripts one by one by simply drag/drop them on the autohotkey.exe from the zip file you downloaded. V2 is still in progress so I wouldn't recommend taking the jump just yet, v2 will break all of your scripts due to syntax changes and also removed/replaced commands (for example StringReplace -> StrReplace to name but one)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 1st, 2012, 11:09 pm 
Offline

Joined: July 20th, 2009, 6:01 am
Posts: 166
Location: Amsterdam
@Guest: Thanks for your advice!! That is extremely useful. So a few more questions. If I pick up the _L version of the COM library somewhere, my scripts will work again? And what will happen if I use a script saved as ANSI with AHK_L Unicode?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, hyper_, immunity, migz99, sjc1000 and 75 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group