Results 1 to 8 of 8
  1. #1
    aroque is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    8

    Searching text file for a specific text and extracting a portion based upon that

    Hello every one ive got a request for some help im sort of a noob and im sure this is pretty simple. but i have many text files that i need to call a specific one/open it, extract a portion of the text based on a field in a form.....then import the text to a Memo field on that form with the press of a button then with the press of another button use that data for printing purposes i can figure all the bells and whistles out i just cant wrap my brain around the extraction portion. here is a sample of the text. i need to search for the text in blue and extract all the text between the green lines if its any help this is a UPS label formatted in ZPL for printing on a Zebra printer. any snippits of code or explanation will be of great help...Thanks in advance :

    ^BY3,,203^FT156,979^BCN,,N^FD>:1ZE9>58953030060867 0^FS
    ^FT10,1038^A0N,24,24^FDBILLING: P/P^FS


    ^FT10,1063^A0N,24,24^FDREF1: 9553327150^FS
    ^FT544,1204^A0N,20,20^FDCUU 11.1 Z140 39.5V 04/2013^FS
    ^FT20,1189^A0N,25,25^FD^FO0,1265 ^GB1200,0,1^FS^FO0,1425 ^GB1200,0,1^FS^FT15,1300 ^A0N,35,35^FDPO : 9553327150^FS^FT420,1300 ^A0N,30,30^FDSHIP DATE: May 09, 2013^FS^FT15,1340 ^A0N,35,35^FDSO : 184266279^FS^FT600,1340 ^A0N,25,25^FDICN : 20836311^FS^FT420,1340 ^A0N,25,25^FDWAVE : 96795^FS^FT15,1380 ^A0N,35,35^FDDPCI: 550091116^FS^FT420,1380 ^A0N,30,30^FDQTY : 6^FS^FT15,1420 ^A0N,35,35^FDITEM: 84190^FS^FT300,1420 ^A0N,22,22^FD SKYLANDERS SA CHARACTER PACK ASSORTMENT (6 COUNT)^FS^FT100,1580 ^A0N,30,30^FD^BY4^BCN,140,N,N^FD>;0020020626020385 6040^FS^FT275,1610 ^A0N,30,30^FD00200206260203856040^FS^FT600,1380 ^A0N,25,25^FDSID : 40551238^FS^FS
    ^XZ~SD20
    ^XA^CI13
    ^LH0,0^FS
    ^PR4,4,2^FS
    ^FT0,1016^GB809,0,20^FS
    ^FT0,758^GB809,0,2^FS
    ^FT0,656^GB809,0,20^FS
    ^FT244,636^GB0,215,2^FS
    ^FT0,421^GB809,0,2^FS
    ^FT20,34^A0N,20,20^FDDISTRIBUTION^FS
    ^FT20,58^A0N,20,20^FD(559) 497ð4300^FS
    ^FT20,82^A0N,20,20^FDACTIVISION BLIZZARD FDC^FS
    ^FT20,107^A0N,20,20^FD4247 SOUTH MINNEWAWA^FS
    ^FT20,131^A0N,20,20^FDFRESNO CA 93725^FS
    ^FT406,51^A0N,40,40^FD2 LBS^FS
    ^FT630,51^A0N,30,30^FD3 OF 8^FS
    ^FT20,219^A0N,30,30^FDSHIP^FS
    ^FT20,260^A0N,30,30^FD TO:^FS
    ^FT122,205^A0N,30,30^FD(559) 497ð4300^FS
    ^FT122,238^A0N,30,30^FDWALMART STORES INC.^FS
    ^FT122,270^A0N,30,30^FD891 ROUTE 9^FS
    ^FT122,303^A0N,30,30^FDWALðMART STORE 2116^FS
    ^FT122,345^A0N,40,40^FDQUEENSBURY NY 12804^FS
    ^FT20,630^BD2^FH^FD003840128040000[)>_1E01_1D961Z00608714_1DUPSN_1DE98953_1E07P3_1DDQ HG9D_1CO*TS+OH4D:9W2L+7GIET2+UG"HWOJ3%H(J_0D_1E_04 ^FS
    ^FT284,496^A0N,71,71^FD NY 128 0ð01^FS
    ^BY4,,102^FT375,620^BCN,,N^FD>;42012804^FS
    ^FT20,711^A0N,50,50^FDUPS GROUND^FS
    ^FT20,740^A0N,25,25^FDTRACKING #: 1Z E98 953 03 0060 8714^FS
    ^FT687,756^GB122,0,100^FS
    ^BY3,,203^FT156,979^BCN,,N^FD>:1ZE9>58953030060871 4^FS
    ^FT10,1038^A0N,24,24^FDBILLING: P/P^FS
    ^FT10,1063^A0N,24,24^FDREF1: 9553327150^FS
    ^FT544,1204^A0N,20,20^FDCUU 11.1 Z140 39.5V 04/2013^FS
    ^FT20,1189^A0N,25,25^FD^FO0,1265 ^GB1200,0,1^FS^FO0,1425 ^GB1200,0,1^FS^FT15,1300 ^A0N,35,35^FDPO : 9553327150^FS^FT420,1300 ^A0N,30,30^FDSHIP DATE: May 09, 2013^FS^FT15,1340 ^A0N,35,35^FDSO : 184266126^FS^FT600,1340 ^A0N,25,25^FDICN : 20835563^FS^FT420,1340 ^A0N,25,25^FDWAVE : 96795^FS^FT15,1380 ^A0N,35,35^FDDPCI: 550091116^FS^FT420,1380 ^A0N,30,30^FDQTY : 6^FS^FT15,1420 ^A0N,35,35^FDITEM: 84190^FS^FT300,1420 ^A0N,22,22^FD SKYLANDERS SA CHARACTER PACK ASSORTMENT (6 COUNT)^FS^FT100,1580 ^A0N,30,30^FD^BY4^BCN,140,N,N^FD>;0020020626020384 8328^FS^FT275,1610 ^A0N,30,30^FD00200206260203848328^FS^FT600,1380 ^A0N,25,25^FDSID : 40551085^FS^FS
    ^XZ~SD20
    ^XA^CI13
    ^LH0,0^FS
    ^PR4,4,2^FS
    ^FT0,1016^GB809,0,20^FS
    ^FT0,758^GB809,0,2^FS
    ^FT0,656^GB809,0,20^FS
    ^FT244,636^GB0,215,2^FS

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    That can be done, what specific parts data between the XA and XZ record are you trying to extract or do you just want to pull the whole section of text? are you going to be doing multiple searches at once or just one tracking ID at a time?

    I'm enclosing a simple example.

    Make sure the three files are in the same folder or it won't work (you can adapt the code to your situation even to cycle through multiple directories in search of file names that meet a criteria)

    aroque.zip

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    One other thing of note, you seem to have a lot of lines that really are not that useful, you can have the script exclude any totally useless lines as well by testing the string for certain substrings and not writing them to the text box if you don't actually need them. You could even parse the lines you want and ignore everything else leaving you with just the information you want.

  4. #4
    aroque is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    8
    Quote Originally Posted by rpeare View Post
    One other thing of note, you seem to have a lot of lines that really are not that useful, you can have the script exclude any totally useless lines as well by testing the string for certain substrings and not writing them to the text box if you don't actually need them. You could even parse the lines you want and ignore everything else leaving you with just the information you want.
    Rpeare,
    Thanks for the good gouge sorry its taken so long to reply they keep me busy at work so i finally got to pear into your code and it works great ive made some minor changes to make it function the way i need to.... i just have one more question if its not to much.... is there a way to search the same data just based on different data on a different line without rewriting the whole thing?....ie: (same file just cut down blue denotes )

    ^FT20,711^A0N,50,50^FDUPS GROUND^FS
    ^FT20,740^A0N,25,25^FDTRACKING #: 1Z E98 953 03 0060 8714^FS
    ^FT687,756^GB122,0,100^FS
    ^BY3,,203^FT156,979^BCN,,N^FD>:1ZE9>58953030060871 4^FS
    ^FT10,1038^A0N,24,24^FDBILLING: P/P^FS
    ^FT10,1063^A0N,24,24^FDREF1: 9553327150^FS
    ^FT544,1204^A0N,20,20^FDCUU 11.1 Z140 39.5V 04/2013^FS
    ^FT20,1189^A0N,25,25^FD^FO0,1265 ^GB1200,0,1^FS^FO0,1425 ^GB1200,0,1^FS^FT15,1300 ^A0N,35,35^FDPO : 9553327150^FS^FT420,1300 ^A0N,30,30^FDSHIP DATE: May 09, 2013^FS^FT15,1340 ^A0N,35,35^FDSO : 184266126^FS^FT600,1340 ^A0N,25,25^FDICN : 20835563^FS^FT420,1340 ^A0N,25,25^FDWAVE : 96795^FS^FT15,1380 ^A0N,35,35^FDDPCI: 550091116^FS^FT420,1380 ^A0N,30,30^FDQTY : 6^FS^FT15,1420 ^A0N,35,35^FDITEM: 84190^FS^FT300,1420 ^A0N,22,22^FD SKYLANDERS SA CHARACTER PACK ASSORTMENT (6 COUNT)^FS^FT100,1580 ^A0N,30,30^FD^BY4^BCN,140,N,N^FD>;0020020626020384 8328^FS^FT275,1610 ^A0N,30,30^FD00200206260203848328^FS^FT600,1380 ^A0N,25,25^FDSID : 40551085^FS^FS
    ^XZ~SD20

    Thanks you have been ALOT of help

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    It depends on the characteristic of the line.

    I'm assuming the part that you've highlighted *always* appears in the A0N line. Does it also appear as the 7th to last field of that line? or can it's physical position in the row vary? If it's always in the same position (by position I am using the carat (^) to denote the beginning/end of a field) then counting backward from the end of the line you have

    NOTE I just tried some test code and realized when I cut and pasted your text the ^AON did not start the line. Can you produce a 2 record test file (don't put real data in it just replace whatever identifies it with some garbage data) so I can work with an actual file?

  6. #6
    aroque is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    8
    Quote Originally Posted by rpeare View Post
    It depends on the characteristic of the line.

    I'm assuming the part that you've highlighted *always* appears in the A0N line. Does it also appear as the 7th to last field of that line? or can it's physical position in the row vary? If it's always in the same position (by position I am using the carat (^) to denote the beginning/end of a field) then counting backward from the end of the line you have

    NOTE I just tried some test code and realized when I cut and pasted your text the ^AON did not start the line. Can you produce a 2 record test file (don't put real data in it just replace whatever identifies it with some garbage data) so I can work with an actual file?
    Rpeare,
    Thanks for looking in to this sorry ive taken so long to reply. i have attached some more data... this is the actual format that i receive the file there minus any sensitive information and once again thank you very muchTest.txt

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I will look at this on friday morning and get back to you

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Does each line in this layout ALWAYS have the same number of fields?
    Does the line always start with FT20,1189?
    Is the line that you're trying to parse ALWAYS 1 line prior to the XZ record?
    Is the line you're trying to parse ALWAYS 1 line after the FT544 line?

    The field that you're trying to extract, is it always the same in each of the two fields that I mentioned previously?
    If so does the first instance of that number ALWAYS have a ; to star the field?
    Do ; marks appear anywhere else in your text file, or more importantly, CAN a semi colon ( appear anywhere on any other FT20 line?

    What you're looking for is an easy way to identify which field of which row you want to extract

    so for instance
    if the portion of the line you're trying to extract always appears in a line that begins with the text "^FT20,1189", further if the field always starts with a semi colon ( it would be really easy to extract it.

    What I'm looking at for you (based on your knowledge of full text files) is *how* can you 100% identify that item you want to extract.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 06-04-2012, 04:31 PM
  2. Bold portion of text in memo field.
    By kenton.l.sparks@gmail.com in forum Access
    Replies: 1
    Last Post: 05-01-2012, 03:32 PM
  3. Extracting text from a field
    By bwash70 in forum Access
    Replies: 4
    Last Post: 11-24-2010, 08:10 PM
  4. Replies: 1
    Last Post: 11-05-2010, 04:31 PM
  5. Extracting text from XML data
    By rob4465 in forum Access
    Replies: 1
    Last Post: 03-18-2010, 06:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums