#40752 - 09/24/12 10:26 AM
Help with script
|
OL Guru
Registered: 05/03/11
Posts: 147
|
You wrote this script for me awhile back. Can you tell me where it is looking for the words Lot Numbers:
function @FindLotNumber():string define(&i, integer, 0) define(&res, string, '')
for(&i, 1, 1, ¤t.lpp) if(pos('Lot Numbers:', @(&i, 9, 20)) > 0) &res := @(&i, 22, 46) exit() endif() endfor() &Result := &res endfunction()
I'm asking because it isn't always picking up the lot number and I think that it might be because it is either over to the left or right or on a different line sometimes, so I'm just trying to figure out what this is doing for sure so that I can try to fix it. I need it to look for the first occurance of lot numbers: and pick up the next characters after that..no matter where it finds it (line or position).
Thanks!!
|
Top
|
|
|
|
#40754 - 09/24/12 10:35 AM
Re: Help with script
[Re: tbradley]
|
OL Expert
Registered: 04/19/10
Posts: 316
Loc: London, UK
|
The 'pos' function is where it is searching for the word 'LotNumbers:' between chars 9 and 20 on line &i. The 'pos' function returns the start position/char if found and if not, it returns 0 so this function is saying if the pos is greater than 0 - i.e. it has found the term 'LotNumbers:' then set the &res variable to whatever is on that line between chars 22 and 46. Finally it outputs that string as the result. Any questions, let me know
Edited by jim3108 (09/24/12 10:36 AM)
|
Top
|
|
|
|
#40755 - 09/24/12 10:40 AM
Re: Help with script
[Re: jim3108]
|
OL Guru
Registered: 05/03/11
Posts: 147
|
Can I make it so it looks anywhere on the line for that text and then takes the next 25 characters? For some reason the data coming in from the 400 must be off a character here or there.
|
Top
|
|
|
|
#40758 - 09/24/12 11:22 AM
Re: Help with script
[Re: tbradley]
|
OL Expert
Registered: 10/14/05
Posts: 4956
Loc: Objectif Lune Montreal
|
tbradley, This looks like something I wrote, judging by the syntax and the way the code is written... To get the next 25 characters after the lot number is found, you could tweak the code to be like this:
function @FindLotNumber():string
define(&i, integer, 0)
define(&res, string, '')
for(&i, 1, 1, ¤t.lpp)
if(pos('Lot Numbers:', @(&i, 1, 500)) > 0)
&res := trim(mid(@(&i, 1, 500), pos('Lot Numbers:', @(&i, 1, 500))+12, 25))
exit()
endif()
endfor()
&Result := &res
endfunction()
This will look for "Lot Numbers:" anywhere on the line(actually looking at characters 1 to 500, which should be enough in most cases) and then return the next 25 characters after "Lot Numbers:", no matter where it is on the line. Hope that helps! Regards, Raphaël Lalonde Lefebvre
|
Top
|
|
|
|
#40759 - 09/24/12 11:23 AM
Re: Help with script
[Re: tbradley]
|
OL Expert
Registered: 04/19/10
Posts: 316
Loc: London, UK
|
Yes of course you can, just change where the pos function looks so if the line is 100 columns long then it should read:
if(pos('Lot Numbers:', @(&i, 1, 100)) > 0)
....
endif()
Then if you want the next 25 characters, then within the if statement you can do the pos again, as it is now true and say:
&res := @(&i, pos('Lot Numbers:', @(&i, 1, 100)) + 12, (pos('Lot Numbers:', @(&i, 1, 100)) + 25))
I think it might be cleaner to store the starting col returned by pos in a temp var though and then use that like this:
&x := pos('Lot Number:', @(&i, 1, 100))
&res := @(&i, &x + 12, &x + 25)
Be sure to define &x at the top of your function as an integer variable and change references to 100 to however many columns make up a line in your example. Regards, James.
Edited by jim3108 (09/24/12 11:24 AM)
|
Top
|
|
|
|
#40761 - 09/24/12 11:38 AM
Re: Help with script
[Re: jim3108]
|
OL Guru
Registered: 05/03/11
Posts: 147
|
Raphael,
You did write it for me originally. :-)
I put in your code above but I am getting an error. It says Error: PTK0041: Uknown operator or not an integer "Pos".
This is what I have
function @FindLotNumber():string define(&i, integer, 0) define(&res, string, '')
for(&i, 1, 1, ¤t.lpp) if(pos('Lot Numbers:', @(&i, 1, 500)) > 0) &res := trim(mid(@(&i, 1, 500), pos('Lot Numbers:' @(&i, 1, 500))+12, 25)) exit() endif() endfor() &Result := &res endfunction()
|
Top
|
|
|
|
#40762 - 09/24/12 11:39 AM
Re: Help with script
[Re: tbradley]
|
OL Expert
Registered: 04/19/10
Posts: 316
Loc: London, UK
|
There is a comma missing!
&res := trim(mid(@(&i, 1, 500), pos('Lot Numbers:' @(&i, 1, 500))+12, 25))
Put the comma after 'Lot Numbers:' and before @
&res := trim(mid(@(&i, 1, 500), pos('Lot Numbers:', @(&i, 1, 500))+12, 25))
Edited by jim3108 (09/24/12 11:43 AM)
|
Top
|
|
|
|
#40763 - 09/24/12 11:51 AM
Re: Help with script
[Re: jim3108]
|
OL Guru
Registered: 05/03/11
Posts: 147
|
Thanks!! I looked over it about 4 times and still didn't see that. Grrrrr. Thanks for your help!!
|
Top
|
|
|
|
|
|