Jump to content


Photo

Script becomes more unreliable as it gets longer


  • Please log in to reply
45 replies to this topic

#1 Rathgar2

Rathgar2
  • Members
  • 59 posts

Posted 10 May 2012 - 12:28 AM

I am attempting to automate a data entry task. It starts as we receive an email in Outlook from a partner company, then is printed out and hand entered into our customer record system. Not only is this super lame, but the email prints out to 2 pages where half of the order is on the 2nd page. I wrote a script that Opens up the email and Sends the key commands the crawl down through the email, deleting empty lines and formatting the fonts and sizes to make data entry easier. Got the script up and running, and was feeling ambitious, and wanted to try to Copy all of that lovely data to a AHK Var Array, and then have AHK transfer clean data to our CRM Onyx. The problem is as my script gets longer it starts to become unreliable, like it doesn't have enough time to wait for Outlook to finish a step before going on to the next. I tried to add additional sleep time and that helped but it now breaks down in random places and becomes unusable and is driving me nuts, because I know it works in baby steps but the more I do the greater the random failures happen. Like I have #1 hotkey that deals with just the email, and I get it to work perfect, but then as I am building the next #2 hotkey, and go back to use #1, it is like all the timing and sleeps are thrown off. Here is a taste of my #1 code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
WinGet, Onyx, List, Onyx Employee Portal - Web Client - Windows Internet Explorer
SetBatchLines, 20ms


; Was a Loop command for 2 Address line regs.  Now saves reg info into a Var Array to automate DP.  Must watch the process and send a pause 

hotkey CTRL+Shift+Z when a 3 Address Line reg is encountered.  Also a Pause at the end of a batch. Background processes that eat a bit of 

CPU resources can easily throw off this Macro. Be ready to CTRL+Shift+Z to reset the macro.  To Activate CRTL+SHIFT+o (o as in Oscar)
^+o::
KeyWait, o
Process, Priority, , High
WGU_Address_Line_2 := ;
Sleep 600
Send {Enter}
Sleep 250
Send {Alt}{Down}{Tab 6}
Sleep 1000
Send {Enter}{Down}{Enter}
Sleep 750
Send {Del 3}{Down}{Del 7}{Down}{Del 5}{Down 5}{Del 10}{Down 3}{Del 10}{Down}{Del 10}{Down}{Del 10}{Down}{Del 5}+^{Home}
; Highlight Top Paragraph
Sleep 500
Send {Alt}
Sleep 100
Send {Right 3}{Down}{Tab 6}8{Enter}{Home}{Down 14}
; Reduce Top Paragraph Size
Send {End}+^{Up}
; Highlight Student Name
Sleep 750
Send {ALT}{Down}
Sleep 1000
Send {Tab 6}16{Enter}
Sleep 100
Send {Home}{Right 14}^+{Right}+{Left}^{c} ;Copy WGU student First Name
Sleep 250
WGU_First_Name := Clipboard
Sleep 100
Send {Right 2}+{End}^c ;Copy WGU student Last Name
Sleep 250
WGU_Last_Name := Clipboard
Sleep 100
Send {Home}{Down}{Del 5}{Down}{End}+^{Up}
; Highlight Student Email
Sleep 750
Send {Alt}
Sleep 100
Send {Down}
Sleep 750
Send {Tab 6}16{Enter}{Home}
Sleep 100
Send {Right 15}+{End}^{c} ;Copy WGU student Email Address
Sleep 100
WGU_Email_Address := Clipboard
Sleep 250
Send {Home}{Down}{Del 5}{Down}{End}+^{Up}
Sleep 100
; Highlight Student ID
Sleep 750
Send {Alt}
Sleep 250
Send {Down}
Sleep 750
Send {Tab 6}16{Enter}{Home}{End}+{Left 4} ;Highlight last 4 digits of Student ID
Sleep 750
Send {Alt}{Down}
Sleep 750
Send {Tab 17}{Enter 2} ;Color last 4 digits of Student ID
Sleep 100
Send {Home}{Right 20}+{End}^{c} ;Copy WGU Student ID#
Sleep 250
WGU_Student_ID := Clipboard
Sleep 100
Send {Home}{Down}{Del 5}{Down 2}{Del 10}{Down}{Del 10}{Down 2}{Del 10}+^{Up 4} ; Highlights the 4 lines of Mentor Info Block
Sleep 750
Send {Alt}{Down}
Sleep 750
Send {Tab 6}8{Enter}{Home}{Down 5}{End}+^{Up} ;Reduce the size of the Mentor Info Block
;; Highlight Address Line 1
Sleep 750
Send {Alt}{Down}
Sleep 750
Send {Tab 6}16{Enter}
Sleep 500
Send {Home}{Right 8}+{End}^{c} ;Copy Address Line #1
Sleep 250
WGU_Address_Line_1 := Clipboard
Sleep 2500 ;Last Chance to interrupt script to run alternate script for a 3 address line reg.
Send {Down}{Del}{Space 8}{End}+^{Up}
Sleep 750
Send {Alt}{Down}
Sleep 750
Send {Tab 6}16{Enter}{Home} ;Highlight and fix Address Line 2 (City, State, Zip)
Sleep 100
Send {Right 8}^+{Right}+{Left}^{c} ;Copy City
Sleep 250
WGU_City := Clipboard
Sleep 100
Send {Right 2}+^{Right}^{c} ;Copy State
Sleep 250
WGU_State := Clipboard
Sleep 100
Send {Right 3}+{End}^{c} ;Copy Zip
Sleep 250
WGU_Zip := Clipboard
Sleep 100
Send {Home}{Down}{Del 5}{Down}{End}+^{Up} ;Hightlight Phone Number
Sleep 750
Send {Alt}{Down}
Sleep 750
Send {Tab 6}16{Enter}{Home}
Sleep 100
Send {Right 22}+^{Right}^{c} ; Copy Telephone number 1 of 3 parts
Sleep 250
WGU_Phone_1of3 := Clipboard
Sleep 100
Send {Right 2}+^{Right}^{c} ; Copy Telephone number 2 of 3 parts
Sleep 250
WGU_Phone_2of3 := Clipboard
Sleep 100
Send {Right 2}+{End}^{c} ; Copy Telephone number 3 of 3 parts
Sleep 250
WGU_Phone_3of3 := Clipboard
Sleep 100
Send {Home}{Down 2}{Del 5}{Down}{Del 2}{Space 8} ;Course Name
Sleep 100
Send {Right 13}+{End}+{Left 6}^{c} ;Copy Course Name
Sleep 250
WGU_Course_Reg := Clipboard
Sleep 100
; Clean up remainder of Email
Send {Home}{Down}{Del 10}{Down}{Del 10}{Down}{Del 10}{Down}{Del 20}{Down}{Del 10}{Down}{Del}{Down}{Del}{Down}{Del 10}{Down}{Del}{Down}
Sleep 250
If (WGU_Course_Reg= "Classroom Mgt for New Teachers/Motivating Today's Learner")
Send WGU-CMNT TC216
else
If (WGU_Course_Reg= "Designing Curriculum and Instruction and Building Your Repertoire of Teaching Strategies")
Send WGU-DCI/IMS/BYRT TC217
else
If (WGU_Course_Reg= "Designing Assessment to Promote Learning")
Send WGU-DAP TC218
else
If (WGU_Course_Reg= "Reading: Part One/Foundations; Part Two/Teaching Reading in the Elem. Grades")
Send WGU-FRL TC219
else
If (WGU_Course_Reg= "MATH: Teaching for Understanding")
Send WGU-MATH TC220
else
Sleep 250
Send +{Home}{Alt}{Down}
Sleep 750
Send {Tab 6}28{Enter} ;Increase Font Size
Sleep 250
Send {Alt}{Down}
Sleep 750
Send {Tab 28}{Enter}^{b} ;Center & Bold
;Sleep 250
;Send ^s ;Save Reg
;Sleep 1000
;Send ^p ;Print Reg
;Sleep 500
;Send {Enter}
;Sleep 1500
;Send !{F4} ;Close reg
;Sleep 500
;Send {Down} ;Move Down in Outlook folder
return
And here is #2
; Test Macro to populate WGU Var Array to a fresh blank Onyx customer page. CTRL+SHIFT+1
^+1::
KeyWait, 1
Sleep 100
WinActivate, ahk_id %Onyx1%
Sleep 200
MouseClick, Left, 360, 142 ;Click Customer Power Page
Sleep 200
MouseClick, Left, 1003, 239 ;Click the Onyx "White Plus" icon
Sleep 250
ImageSearch, ONYX_Ind_X1, ONYX_Ind_Y1, 0, 0, A_ScreenWidth, A_ScreenHeight, *100 Onyx_Ind.bmp
Sleep 50
MouseClick, Left, ONYX_Ind_X1+5, ONYX_Ind_Y1+8
Sleep 100
Send {Tab}{Enter}
Sleep 3000
ImageSearch, ONYX_White_Plus_X1, ONYX_White_Plus_Y1, 0, 0, A_ScreenWidth, A_ScreenHeight, *100 Onyx_White_Plus1.bmp
Sleep 50
MouseClick, Left, ONYX_First_Name_X1+35, ONYX_White_Plus_Y1+5 ;Click the Onyx "White Plus" icon inside the secondary search screen to get 

inside the blank new individual screen.
Sleep 1000
ImageSearch, ONYX_First_Name_X1, ONYX_First_Name_Y1, 0, 0, A_ScreenWidth, A_ScreenHeight, *100 ONYX_First_Name.bmp
Sleep 50
MouseClick, Left, ONYX_First_Name_X1+80, ONYX_First_Name_Y1+10 ;Click the Onyx First Name Field
Send %WGU_First_Name%
Sleep 100
Send {Tab 2}%WGU_Last_Name%
Sleep 100
Send {Tab}%WGU_Phone_1of3%
Sleep 100
Send ^a^c{Del} ; Copy And Clear Tel# 1of3
ImageSearch, ONYX_New_Phone_X1, ONYX_New_Phone_Y1, 0, 0, A_ScreenWidth, A_ScreenHeight, *100 ONYX_New_Phone.bmp
Sleep 50
MouseClick, Left, ONYX_New_Phone_X1+50, ONYX_New_Phone_Y1+10 ;Click the Onyx Tel# Field
Sleep 100
Send ^V ; Paste part 1 of Tel#
Sleep 100
MouseClick, Left, ONYX_First_Name_X1+80, ONYX_First_Name_Y1+10 ;Click the Onyx First Name Field
Sleep 100
Send {Tab 3}%WGU_Phone_2of3%^a^c{Del} ; Copy And Clear Tel# 2of3
Sleep 250
MouseClick, Left, ONYX_New_Phone_X1+100, ONYX_New_Phone_Y1+10 ;Click the Onyx Tel# Field
Sleep 100
Send ^V ; Paste part 2 of Tel#
Sleep 100
MouseClick, Left, ONYX_First_Name_X1+80, ONYX_First_Name_Y1+10 ;Click the Onyx First Name Field
Sleep 100
Send {Tab 3}%WGU_Phone_3of3%^a^c{Del} ; Copy And Clear Tel# 3of3
Sleep 250
MouseClick, Left, ONYX_New_Phone_X1+120, ONYX_New_Phone_Y1+10 ;Click the Onyx Tel# Field
Sleep 100
Send ^V ; Paste part 3 of Tel#
Return
To get the whole thing to be useful it has to get longer, so this is just gonna get worse unless someone knows a solution. Thanx in advance...

#2 engunneer

engunneer
  • Fellows
  • 9162 posts

Posted 10 May 2012 - 12:41 AM

Don't rely just on sleeps. If the sleep is to wait for a window to get active, use WinWaitActive, etc.

#3 Rathgar2

Rathgar2
  • Members
  • 59 posts

Posted 10 May 2012 - 03:30 PM

Sadly, all of the steps of the script are taken inside of an email in Outlook. It is almost as if the larger the txt/ahk file gets the more timing is altered. It feels like that there is like a pool of allotted time for the entire ahk file and that the more script lines I insert it starts to steal time from somewhere else. It is very frustrating to have a script working perfectly, only to come back to it later after writing more code and have it fail when I did not change anything!

#4 engunneer

engunneer
  • Fellows
  • 9162 posts

Posted 10 May 2012 - 04:14 PM

i think you might not want to set your script to high priority
that means it is higher than outlook

instead of doing all the email editing in outlook, can you just have the script copy it to the clipboard, and do all the parsing as text, then paste it back to outlook?

Might be a different approach, but then not relying on outlook to keep up.

#5 Rathgar2

Rathgar2
  • Members
  • 59 posts

Posted 10 May 2012 - 04:31 PM

Ohhhh, I did not think of that. So you think I should copy the text out of the Outlook Email, and paste them to a Notepad to do the editing? Or are you describing a method that does that inside of the memory cache inside the clipboard where it is not actually displayed and just outputted when done? I can imagine loads of improvment inside of Notepad, but if there is a way to do it in memory then that works even better, maybe.

#6 engunneer

engunneer
  • Fellows
  • 9162 posts

Posted 10 May 2012 - 04:44 PM

i was suggesting doing it in script memory

I recommend the TF library from hugoV (<!-- m -->http://www.autohotkey.net/~hugov/<!-- m -->) as a useful text parsing tool
...
Send, ^a
Sleep, 100
Send, ^x
Sleep 3000
Original := Clipboard

;stuff to modify original, such as StringReplace, TF_RangeReplace, etc (save to new var)

Clipboard := Modified
Sleep, 3000
Send, ^v


#7 Rathgar2

Rathgar2
  • Members
  • 59 posts

Posted 11 May 2012 - 08:25 PM

Using your suggestion with the TF library I have made great strides towards my next goal of taking the emailed orders, stripping the actual data from them and the doing something useful with it (Like order entry automation). Here is my new code so far:
; CRTL+SHIFT+o (o as in Oscar) Start in Outlook Shared ROLE account for WGU Regs.
^+o::
KeyWait, o
F:="WGUReg1.txt"
F2:="WGUReg2.txt"
Sleep 500
Send {Enter} ;Open Email
Sleep 250
Send ^a^c  ; Highlight All and Copy
Sleep 250
WGURaw := Clipboard
FileDelete, WGUReg1.txt
FileAppend, %WGURaw%, WGUReg1.txt          ;create raw txt file with the WGU Reg
TF_RemoveBlankLines("!" F) 
TF_WhiteSpace("!" F)
WGU_First_Last_Name:=TF_ReadLines(TF(F),14,14)                 ;pass on global var t created by TF(), read lines 14 to 14, asign result to VAR "WGU_First_Last_Name"
WGU_Email:=TF_ReadLines(TF(F),15,15)
WGU_Student_ID:=TF_ReadLines(TF(F),16,16)
WGU_Address1:=TF_ReadLines(TF(F),21,21)
WGU_City_State_Zip:=TF_ReadLines(TF(F),22,22)
WGU_Telephone:=TF_ReadLines(TF(F),23,23)
WGU_Course_Reged:=TF_ReadLines(TF(F),25,25)
Sleep 500
WGURaw2 =
(join
%WGU_First_Last_Name%
%WGU_Email%
%WGU_Student_ID%
%WGU_Address1%
%WGU_City_State_Zip%
%WGU_Telephone%
%WGU_Course_Reged%
)
FileDelete, WGUReg2.txt
FileAppend, %WGURaw2%, WGUReg2.txt 
; Here we clean the data
TF_TrimLeft("!" F2,"1","1",6)                ; Trim Left 6 Characters in line 1 for "Name: " removal
TF_TrimLeft("!" F2,"2","2",7)                ; Trim Left 7 Characters in line 2 for "Email: " removal
TF_TrimLeft("!" F2,"3","3",12)               ; Trim Left 12 Characters in line 3 for "Student ID: " removal
TF_TrimLeft("!" F2,"6","6",14)                ; Trim Left 14 Characters in line 6 for "Phone Number: " removal
TF_TrimLeft("!" F2,"7","7",13)                ; Trim Left 13 Characters in line 7 for "Course Name: " removal
TF_TrimRight("!" F2,"7","7",5)                ; Trim Right 5 Characters in line 7 for "(XXX)" removal
IfWinNotExist, WGUReg2.txt
Run WGUReg2.txt
else
WinActivate, WGUReg2.txt
Return

What this does is takes this ugly text:
PROVIDER_NOTIFICATION
***IMPORTANT***
The student listed below has paid for and enrolled in one of the courses offered
by your institution through Wessfdtern Govefdsrnors Univesdfsrsity. This student must now
be entered in your institution's student information system (SIS). The student should
receive the same notification of class meetings, syllabus, materials, URL, passwords,
etc. as is necessary for other students enrolled directly through your institution.
You were listed in your institution's application to WGU as the Contact for Student
Enrollments. If you are unsure of your role with WGU or how to proceed with this
student enrollment, please contact the WGU Principal Contact at your institution.
Thank you for your time and attention to this matter.
Wesiydtern Govedsfsdrnors Univefdsfrsity
Student Information
Name: Kathy Mort
Email: mrtym@my.wgu.edu
Student ID: 000xxx2880
Mentor: Sally Mae
Mentor Email: Smae@wgu.edu
Address (In the case of multiple addresses, ship to the street address (#2 address)
listed below):
15557 W Elmssdfsngs St
Delta ID, 83713
Phone Number: 909-555-1204
Course Information
Course Name: Classroom Mgt for New Teachers/Motivating Today's Learner(CG2)
Course Number: 7514
Provider Course Number:
Start Date: Open End Date: Open
Thank you!
Learning Resources Coordinator
Westdfhhgfern Govegfhgfrnors Univehgfhgfsity
4001 Sohgfuth 700 Egfhgast, Suite 700
Sagfhgflt Lagfke Chgfity UT 84107
Learningfgr@wgufghgf.edu
And strips it all down to this clean data:
Kathy Mort
mrtym@my.wgu.edu
000xxx2880
15557 W Elmssdfsngs St
Delta ID, 83713
909-555-1204
Classroom Mgt for New Teachers/Motivating Today's Learner
This is great! Next I need to break this up further to store each piece to a separate Var. This way I can get another script to paste First Name, Last Name, City, State, Zip. separately in our order system to create a new customer. Trouble I am having is trying to figure out how to either have the script insert Carriage Returns to selectively put each bit on a separate line so I can store em to a Var. Or I need to figure out how to make different Vars from 1 line. Or the grunt way, open the txt and do this:
; Here is where we begin breaking up the WGU Data into ONYX Pastable bits.
;Send {Home}{Right 6}^+{Right}+{Left}^{c} ;Copy WGU student First Name
;Sleep 250
;WGU_First_Name := Clipboard
;Sleep 100
;Send {Right 2}+{End}^c ;Copy WGU student Last Name
;Sleep 250
;WGU_Last_Name := Clipboard
;Sleep 100
;Send {Home}{Down}
;Sleep 100
;Send {Right 7}+{End}^{c} ;Copy WGU student Email Address
;Sleep 100
;WGU_Email_Address := Clipboard
;Sleep 100
;Send {Home}{Down}{Right 12}+{End}^{c} ;Copy WGU Student ID#
;Sleep 250
;WGU_Student_ID := Clipboard
;Sleep 100
;Send {Down}{Home}+{End}^{c} ;Copy Address Line #1
;Sleep 250
;WGU_Address_Line_1 := Clipboard
;Sleep 100
;Send ^+{Right}+{Left}^{c} ;Copy City
;Sleep 250
;WGU_City := Clipboard
;Sleep 100
;Send {Right 2}+^{Right}^{c} ;Copy State
;Sleep 250
;WGU_State := Clipboard
;Sleep 100
;Send {Right 3}+{End}^{c} ;Copy Zip
;Sleep 250
;WGU_Zip := Clipboard
;Sleep 100
Which is slow and can get off track easily. I would rather split the data each to a line then use TF_ReadLines to store them to a Var, but I need to be able to split the data And account for hyphenated Last Names and Multi-word City Names like "New York". Any ideas?

#8 RaptorX

RaptorX
  • Members
  • 718 posts

Posted 11 May 2012 - 08:43 PM

not sure if this is what you want but here is an example... i am assuming all the data is in one variable:

var =
(
Kathy Mort
mrtym@my.wgu.edu
000xxx2880
15557 W Elmssdfsngs St
Delta ID, 83713
            909-555-1204      
Classroom Mgt for New Teachers/Motivating Today's Learner
)

info := {}

Loop, Parse, var, `n, `r ; divide that variable by new lines, ignore carriage returns
    msgbox a_loopfield

; instead of the msgbox you can do something like:
; info[a_index] := a_loopfield
; then access the information in info.1, info.2, info.3 and so on.


If you want something more fancy you can store the info in the object like:
info.name
info.phone

but that requires a bit more code. tell me if you want it that way, i will show you how to do it. :)

#9 engunneer

engunneer
  • Fellows
  • 9162 posts

Posted 11 May 2012 - 08:44 PM

Kathy Mort
mrtym@my.wgu.edu
000xxx2880
15557 W Elmssdfsngs St
Delta ID, 83713
909-555-1204
Classroom Mgt for New Teachers/Motivating Today's Learner
already has carriage returns (`n in AHK land)

FileRead, filedata, WGUReg2.txt
StringSplit, line, filedata, `n, `r
Msgbox, found %var0% lines!
myUser := var1
myEmail := var2

;..etc.

am i misunderstanding?

#10 Rathgar2

Rathgar2
  • Members
  • 59 posts

Posted 11 May 2012 - 11:25 PM

Yeah, I am not certain you are groking. I started by just copying your example and was not getting any results, but I learned a bit from your code, here is how I set it up to get it working:
StringSplit, line, filedata, `n, `r
myUser := line1
myEmail := line2
Msgbox, Vars present %myUser% , %myEmail%
And I get a Var for each of the 7 lines. Which is useful so if nothing else this puts me ahead a bit. What I am aiming for is a way to get the First Name, Last Name, City, State & Zip into separate Vars. Since they are currently all on one line they are not being put into the Var array separately but at the same time to not put the street address on separate Vars.
Kathy Mort
<!-- e --><a href="mailto:mrtym@my.wgu.edu">mrtym@my.wgu.edu</a><!-- e -->
000xxx2880
15557 W Elmssdfsngs St
Delta ID, 83713
909-555-1204
Classroom Mgt for New Teachers/Motivating Today's LearnerWhat I did at first was to open this up in notepad and by using combos of...

^+{Right}
+{End}
{End}+^{Left}
etc..
...to navigate each word ^c it and var := Clipboard it to get the desired things into the Vars. This sux, but can work, with patience. But there has got to be a way to turn the above 7 lines into 12:

Kathy
Mort
<!-- e --><a href="mailto:mrtym@my.wgu.edu">mrtym@my.wgu.edu</a><!-- e -->
000xxx2880
15557 W Elmssdfsngs St
Delta
ID
83713
909
555
1204
Classroom Mgt for New Teachers/Motivating Today's Learner
Well thanx in advance, as I said above you suggestion still puts me ahead so Thanx again as well!

#11 RaptorX

RaptorX
  • Members
  • 718 posts

Posted 14 May 2012 - 07:25 AM

there is an easy way, but it relies on two things:

1) that the city and zip code are always in the 5th line
2) that phone numbers are always divided by dashes (-)

If those two things are constant i can make a script for you that will do that.

#12 Rathgar2

Rathgar2
  • Members
  • 59 posts

Posted 14 May 2012 - 03:38 PM

Well yes the City+State+Zip are always on the 5th line (I have planned a second script to count the lines so I can run an alternate script to cope with the inevitable 2 address line that pushes the City+State+Zip to line 6) and the Telephone number is always separated by dashes. I would very much like to try your script RaptorX.

#13 RaptorX

RaptorX
  • Members
  • 718 posts

Posted 14 May 2012 - 06:02 PM

Here is the code i was talking about. It can be improved GREATLY. I just coded it simply as an example... so keep researching (time allowing it) and improve it!! :)

user := {} ; im using an object here just for the sake of it... its not needed you can put the variables however you want :)
data =
(
Kathy Mort
mrtym@my.wgu.edu
000xxx2880
15557 W Elmssdfsngs St
Delta ID, 83713
909-555-1204      
Classroom Mgt for New Teachers/Motivating Today's Learner
)

StringSplit, data, data, `n,`r
RegexMatch(data1, "(\w+).(.*)", name)                   ; catching the names
RegexMatch(data5, "(\w+).(\w{2}).+?(\d+)", location)    ; splitting the city, state and zipcode
RegexMatch(data6, "(\d+).(\d+).(\d+)", num)             ; splitting the phone number

user.fName:=name1, user.lName:=name2, user.eMail:=data2, user.ID:=data3
user.Address:=data4, user.City:=location1, user.State:=location2, user.ZipCode:=location3
user.ph1:=num1,user.ph2:=num2,user.ph3:=num3, user.slogan:=data7

msgbox % "Name:`t`t" user.fName "`n"
       . "Last Name:`t" user.lName "`n"
       . "Phone Number:`t" user.ph1 " " user.ph2 " " user.ph3 "`n"
       . "Email Address:`t" user.eMail "`n"
       . "Address:`t`t" user.Address "`n`t`t" user.City " " user.State ", " user.ZipCode "`n`n"
       . user.Slogan

; now you can play with the data as much as you want :)


#14 Rathgar2

Rathgar2
  • Members
  • 59 posts

Posted 14 May 2012 - 07:30 PM

I keep getting an error msg saying "The following variable name contains an illegal character: "user.ph2"" Seems to be where ever there is a period in a Var. Taking the time to jigger them around. I think you meant me to find this as you just quickly coded an example for me. I am not certain why a period is an illegal character, maybe an underscore would have not triggered this...

Meanwhile my mind is having a bit of a slow time understanding why this works, but it seems to be doing just that. After jiggering the code and taking out the periods I got a clean looking msg box with the info parsed and lined up. Here is my code:
FileRead, filedata, WGUReg2.txt
StringSplit, WGUline, filedata, `n, `r
RegexMatch(WGUline1, "(\w+).(.*)", name)                   ; catching the names
RegexMatch(WGUline5, "(\w+).(\w{2}).+?(\d+)", location)    ; splitting the city, state and zipcode
RegexMatch(WGUline6, "(\d+).(\d+).(\d+)", num)             ; splitting the phone number
WGUfName:=name1, WGUlName:=name2, WGUeMail:=WGUline2, WGUID:=WGUline3
WGUAddress:=WGUline4, WGUCity:=location1, WGUState:=location2, WGUZipCode:=location3
WGUph1:=num1, WGUph2:=num2, WGUph3:=num3, WGUCourseReg:=WGUline7

msgbox % "Name:`t`t" WGUfName "`n"
       . "Last Name:`t" WGUlName "`n"
       . "Phone Number:`t" WGUph1 " " WGUph2 " " WGUph3 "`n"
       . "Email Address:`t" WGUeMail "`n"
       . "Address:`t`t" WGUAddress "`n`t`t" WGUCity " " WGUState ", " WGUZipCode "`n`n"
       . WGUCourseReg
The part I am not yet groking is in purple:
RegexMatch(WGUline1, [color=#8000FF]"(\w+).(.*)"[/color], name)
RegexMatch(WGUline5, [color=#8000FF]"(\w+).(\w{2}).+?(\d+)"[/color], location)
RegexMatch(WGUline6, [color=#8000FF]"(\d+).(\d+).(\d+)"[/color], num)
I will keep researching the docs on RegexMatch to understand why this works. I can see how to take this direction in the coding to deal with the offset that will occur with addresses that have two lines. Another speed bump is where the City is a multi word article. Like "Salt Lake City", "Palo Alto", "White Sands", "Miami Beach" and "New York City." Would it be possible to have the script use the comma that always appears after the State to backwards offset and get the city name as a whole no matter how many words it was? Thanx already.

#15 engunneer

engunneer
  • Fellows
  • 9162 posts

Posted 14 May 2012 - 07:55 PM

if you are getting errors for having a . in your name, it is because you are using AHK basic instead of AHK_L (l.autohotkey.net). 99% of AHK basic scripts work in _L, so you may as well upgrade to that version

As afar as regex. It can be tricky to grok. (\d+).(\d+).(\d+) is three sets of any set of digits separated by a single char each. Technically it can find a match for all of these:
555.867.5309
555-867-5309
1-2345-54234
(142)236-8431
31984984.189849873.18948943

but it won't catch
5558675309
(123) 867-5309
so you may have to tweak it a bit to not catch bad numbers, but still catch other good numbers.

if you set the item for line5 to be greedy, it should handle multi word city names.

If you google a bit, there are sites full of handy regex patterns, for example for checking an email address. All kinds of programs need address parsing, so i'm sure you can find some well crafted regexes out there.