AutoHotkey Community

It is currently May 27th, 2012, 4:26 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: February 24th, 2010, 8:26 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
I am using COM to read some customer information from one of our tools, and a parse loop to split it into individual bits for output/reporting ect.

---> My issue is, sometimes the 4th field of the msgbox or report data will contain all of the parse data. This only happens if field 4 is blank. If it is blank, it instead gets filled with ALL the information. If it is NOT blank, it contains what it should naturally contain.

Code:
;code I  am using
Clipboard := COM_Invoke(pwb,"document.getElementById[divInfo].innerText")

Loop, parse, Clipboard, `n,
If A_LoopField is not Space
{
   Info := (Info = "") ? A_LoopField : Info . "`n" . A_LoopField
   If (A_Index = 4)   
      Break
}
   
StringSplit, Info, Info, `n

;and mgsbox out as a test with this:

   msgbox,
   (
   CustName: %Info1%
   Address1: %Info2%
   Address2: %Info3%
   Address3: %Info4%
   Acct Num: %AcctNum1%
   .......
   )



Example1:
Name: Joe Shmoe
Addr1: 123 Fake St
Addr2: Apartment 0
Addr3: Townsville, CA
Acct#: 12345678931216549874321
TN1: 555-555-1234
TN2: 555-555-1235


Example2:
Name: Joe Shmoe
Addr1: 123 Fake St
Addr2: Townsville, CA (no appartment)
Addr3: <blank>
Acct#: 12345678931216549874321
TN1: 555-555-1234
TN2: 555-555-1235


Example 1 works fine, everything pases to the msgbox as intended. It has the name, and all three bits of address information.

However- Example2, if that 4th loop field (or third address bit, technically) is blank... the msgbox gets messed up. The msgbox will output everything EXCEPT on line 4/addr3.... that line contains ALL the data. It is like double posting, see example3 below

Example3:
[[This is the msgbox result, note line 4]]
Name: Joe Shmoe
Addr1: 123 Fake St
Addr2: Townsville, CA (no appartment)
Addr3: Name: Joe ShmoeAddr1: 123 Fake StAddr2: Townsville, CAAcct#: 12345678931216549874321
Acct#: 12345678931216549874321
TN1: 555-555-1234
TN2: 555-555-1235



So, the Addr3 line actually contains ALL the data that the msgbox pops up. The other lines, Addr2, Addr1, name, acct, TN... still populate as needed.




Thoughts?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 9:23 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Hmm...maybe this?


Code:
Clipboard := COM_Invoke(pwb,"document.getElementById[divInfo].innerText")

Loop, parse, Clipboard, `n,
If A_LoopField is not Space
{
   Info .= ((A_Index=1) ? "" : "`n") A_LoopField
   If (A_Index = 4)   
      Break
}
   
StringSplit, Info, Info, `n

;and mgsbox out as a test with this:

   msgbox,
   (
   CustName: %Info1%
   Address1: %Info2%
   Address2: %Info3%
   Address3: %Info4%
   Acct Num: %AcctNum1%
   .......
   )


EDIT: Corrected the ternary, please try it again.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Last edited by sinkfaze on February 24th, 2010, 11:08 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 10:20 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
The actual code you posted gives an error becuase it is missing an ')', I changed it to Info .= (A_Index=1 ? "" : "`n") ? A_LoopField which also doesn't work, it makes 1,2,3 and 4 empty, as oppsed to 3 or 4.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 10:24 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
For what its worth (haven't looked at your question really) for parsing loops I ALWAYS use
Code:
Loop, parse, Clipboard, `n, `r
just to be sure the A_LoopField doesn't include the `r char which may cause issues... my 2cts

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 10:27 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
I corrected the code Carcophan, try it again.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 10:46 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
hugov wrote:
For what its worth (haven't looked at your question really) for parsing loops I ALWAYS use
Code:
Loop, parse, Clipboard, `n, `r
just to be sure the A_LoopField doesn't include the `r char which may cause issues... my 2cts


@HugoV
Good point, I need to be in that habbit too. Thanks.
(Didn't change the script results though)

@Sinkfaze
Tried the corrected changes, lines 1 2 3 and 4 are now all blank, but lines 5+ still work. I am not questioning your help, but I have a 'question' about it. Why would you put a_index=1 up front? As opposed to adding the index number to the end of 'info'


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 11:13 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Sorry Carcophan, it needed correcting again (off day :oops: ), try it again. All this is:

Code:
((A_Index=1) ? "" : "`n")


Is a ternary designating when newlines will be inserted. On the first iteration of the parsing loop, presumably the variable we're saving to is blank so no newline will need to be inserted but for every iteration after that one is needed. So in a four-iteration parsing loop that ternary will do this:

ternary pattern wrote:
A_LoopField "`n" A_LoopField "`n" A_LoopField "`n" A_LoopField

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 4:53 am 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
sinkfaze wrote:
Sorry Carcophan....


Ha. Look, don't apologize, I appreciate the help. I will run this tomorrow when I get in. Your latest example/explanation actually makes a lot of sense the way you worded it. Thanks boss.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 7:56 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
So I've finally had a chance today to play around with this.

Sadly the latest example also does not work. I did notice though, when rereading your comment:
Quote:
presumably the variable we're saving to is blank so no newline will need to be inserted


did you mean the variable itself, or the field in which is trying to populate the variable WITH data?

Field #1, #2 and #3 should 'always' contain data, field #4 is the 'optional' one. Field #4 would only ever have content if the customers dwelling is an apartment or needs other address information.

I have changed the loop break from index=4 to index=3, and works as a temporary fix. Downside is changing it to '3' cuts off information WHEN there is the 4th field, but as most accounts only have 3.... i can live with a few accounts missing 1 bit of info.

The A_Index being up front though, will always display 1,2,3 and 4 as blank for some reason. Which is probably happening becuase we are assuming variable1 is blank.


I wish I could just take a screenshot of the msgbox sample to show you exactly how the code come up in field4 in error, but cannot bc of security stuff. :cry:



Code:
;as an example, I have tried the following and other variations

   CustInfo := (CustInfo = "") ? A_LoopField : CustInfo . "`n"  . A_LoopField   ;works as long as index=3/break, index=4 causes error
   ;CustInfo .= (A_Index=1 ? "" : "`n") ? A_LoopField   
   ;CustInfo .= ((A_Index=1) ? "1" : "`n") ? A_LoopField
   ;CustInfo := ((A_Index=1) ? "`n" : "") ? A_LoopField 
   ;CustInfo := ((A_Index=1) ? "`n" : "")
   ;CustInfo := (CustInfo = "") ? A_LoopField : CustInfo . "`n"  . A_LoopField
   ;CustInfo := ((A_Index=1) ? "`n" : "") ? A_LoopField : CustInfo . "`n"  . A_LoopField
   ;CustInfo := ((CustInfo = "") ? "`n" : "") ? A_LoopField : CustInfo . "`n"  . A_LoopField

   If (A_Index =3)  ; || CustInfo4 = "")    ;shouldn't be 'three', bc there are 4 address fields
      Break
;If (A_Index = 4)   ;works if only 3 address fields, 4th filled with error
      ;Break

;If (A_Index =3 || CustInfo4 = "")       ;nope   
;Break



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 7:59 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Can you post a sample of what's in the variable before you attempt to parse it (both with and without the blank field)?

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 8:39 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
We have our famous tool, that I have hinted at various times in the past. The Kiosk style IE page, that is a skin for an old DOS-type database.
Data is all over the place, but house/customer info is in a set location. The address/house/customer info is also always (luckly) in the same order.

Information in our tool, displays as follows::
Name (Line1 = First/Last)
Address (Line2= Street)
Address (Line3= TOWN/zip, unless it is an appartmnet, then it is the appt #)
Address (Line4= TOWN if there was an appartment number in line 3, BLANK if no apparment)


Rough sample IF A_INDEX=4:

1.) Joe Blow
2.) 123 Fake St
3.) Apt #7D
4.) Townsville, XY 12345
5.) Account number
6 - 10) Whatever else, working with/without index=4

1.) Joe Blow
2.) 123 Fake St
3.) Townsville, XY 12345
4.) <contains data for fields 5, 6, 7, 8 ,9 and 10>
5.) Account number
6 - 10) Whatever else, working with/without index=4


Changing a_Index to 3, removed an/all content that would be displayed in line #4. So in theory it would cut off the persons Town name/state/zip, just becuase they do not live in an appartment building.




Quote:
Can you post a sample of what's in the variable before you attempt to parse it (both with and without the blank field)?

I just used the line "Clipboard := COM_Invoke(pwb,"document.getElementById[divCustInfo].innerText")" and msgbox % clipboard.
The msgbox, exactly as it appears with no parse/delimiting(with fake info obviously):
Code:
Homer Simpson
123 Fake Street
SpringField, XY 01234
Account: 123456789123456789SSN: XXX-XX-XXXXHome Phone: (123) 123-1234Other Phone: (000) 000-0000Email Address: xyz@somewhere.commSecondaryEmail: noneBilling Address


Code:
Homer Simpson
123 Fake Street
Unit# 69-F
SpringField, XY 01234
Account: 123456789123456789SSN: XXX-XX-XXXXHome Phone: (123) 123-1234Other Phone: (000) 000-0000Email Address: xyz@somewhere.commSecondaryEmail: noneBilling Address


Note the white space, and lack of it, between the data past account number.

Also, notice the name on line 1, address on 2 and 3. The -ONLY- difference between this msgbox and one with an 'appartment' is that the appartment info will be up there. The remaining data from 'account number' to the end.... is in that long single string, missing whitespace and stuff, as shown.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 10:31 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
This one is bizarrely more difficult than it looks. A parsing loop is not sufficient, since it will only loop for the number of delimiters found; similar a while loop will also not work for the same reason. If the number of loop iterations is less than the amount of variables needed the task simply becomes too cumbersome to work with well. What you have to do is create a pseudo while loop that can work based off of the number of delimiters in the file (in this case, newlines). If there are 4 newlines then there is data in the apartment field; if only three it is blank, Here are two tests of the code:

Code:
var=
(
Homer Simpson
123 Fake Street
Unit# 69-F
SpringField, XY 01234
Account: 123456789123456789SSN: XXX-XX-XXXXHome Phone: (123) 123-1234Other Phone: (000) 000-0000Email Address: xyz@somewhere.commSecondaryEmail: noneBilling Address
)
RegExReplace(var,"`n","`n",e) ; counts the number of newlines and saves to var 'e'
Pos=1 ; needed for pseudo while loop
Loop 4 {
   if (A_Index=3) && (e=3) { ; if A_Index is 3 and 3 newlines (no apt field)
      line%A_Index%:=""
      continue
   }
   Pos:=RegExMatch(var,"s).*?`n",m,Pos+StrLen(m))
   line%A_Index%:=RegExReplace(m,"`n")
}
RegExMatch(var,"s).*",line5,Pos+StrLen(m))
MsgBox, % "Name: " line1
. "`nAddress1: " line2
. "`nAddress2: " line3
. "`nAddress3: " line4
. "`nOther: " line5
return


Code:
var=
(
Homer Simpson
123 Fake Street
SpringField, XY 01234
Account: 123456789123456789SSN: XXX-XX-XXXXHome Phone: (123) 123-1234Other Phone: (000) 000-0000Email Address: xyz@somewhere.commSecondaryEmail: noneBilling Address
)
RegExReplace(var,"`n","`n",e) ; counts the number of newlines and saves to var 'e'
Pos=1 ; needed for pseudo while loop
Loop 4 {
   if (A_Index=3) && (e=3) { ; if A_Index is 3 and 3 newlines (no apt field)
      line%A_Index%:=""
      continue
   }
   Pos:=RegExMatch(var,"s).*?`n",m,Pos+StrLen(m))
   line%A_Index%:=RegExReplace(m,"`n")
}
RegExMatch(var,"s).*",line5,Pos+StrLen(m))
MsgBox, % "Name: " line1
. "`nAddress1: " line2
. "`nAddress2: " line3
. "`nAddress3: " line4
. "`nOther: " line5
return

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 11:16 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
Dumb question, but can I just plug in my 'clipboard' variable inplace of the 'var' variable?

and I should also be able to .= the values of my other regex stuff, output 'line1, line2, line3, line4, regexVar1, regexVar2, var3...'


I didn't think it would turn into something so complicated. Thanks for all your time with this boss. I can't test this till tomorrow again, but it makes a lot of sense the way you layed it out.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 12:03 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Yes you could just replace var with Clipboard to test.

Carcophan wrote:
and I should also be able to .= the values of my other regex stuff, output 'line1, line2, line3, line4, regexVar1, regexVar2, var3...'


Well, the pseudo-while loop only concerns itself with vars 1 through 4, you could match for other info, like this:

Code:
var=
(
Homer Simpson
123 Fake Street
SpringField, XY 01234
Account: 123456789123456789SSN: XXX-XX-XXXXHome Phone: (123) 123-1234Other Phone: (000) 000-0000Email Address: xyz@somewhere.commSecondaryEmail: noneBilling Address
)
RegExReplace(var,"`n","`n",e)
Pos=1
Loop 4 {
   if (A_Index=3) && (e=3) {
      line%A_Index%:=""
      continue
   }
   Pos:=RegExMatch(var,"s).*?`n",m,Pos+StrLen(m))
   line%A_Index%:=RegExReplace(m,"`n")
}
RegExMatch(var,"is)(?<=Account: ).*(?=SSN:)",Acct)
RegExMatch(var,"is)(?<=Home Phone: ).*(?=Other Phone:)",HomePh)
RegExMatch(var,"is)(?<=Email Address: ).*(?=SecondaryEmail:)",Email)
MsgBox, % "Name: " line1
. "`nAddress1: " line2
. "`nAddress2: " line3
. "`nAddress3: " line4
. "`nAccount: " Acct
. "`nHome Phone: " HomePh
. "`nEmail: " Email
return

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 1:08 am 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
sinkfaze wrote:
RegExMatch(var,"is)(?<=Account: ).*(?=SSN:)",Acct)
RegExMatch(var,"is)(?<=Home Phone: ).*(?=Other Phone:)",HomePh)
RegExMatch(var,"is)(?<=Email Address: ).*(?=SecondaryEmail:)",Email)


This is actually very close to the code I was planning on using (am using thanks to a coworker) !!
me wrote:
RegExMatch( Clipboard, "Account: (.*)SSN:", AcctNum)
RegExMatch( Clipboard, "Home Phone: (.*) Other", HomePhone)
.....



Real trick will be, when I figure out what the difference between your and my examples. I need to get the CHM out and compare :) !


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Mickers, rbrtryn, Yahoo [Bot] and 67 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