IMPORTANT ANNOUNCEMENT

These forums were permanently set to read-only mode on July 20, 2022. From that day onwards, no new posting or comment is allowed on the site, but the historical content remains intact and searchable.

A new location for posting questions about PlanetPress Suite is now available:

OL Learn - PlanetPress Classic (opens in new tab)

Page 1 of 2 1 2 >
Topic Options
#40752 - 09/24/12 10:26 AM Help with script
tbradley Offline
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, &current.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]
jim3108 Offline
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 smile



Edited by jim3108 (09/24/12 10:36 AM)

Top
#40755 - 09/24/12 10:40 AM Re: Help with script [Re: jim3108]
tbradley Offline
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]
Raphael Lalonde Lefebvre Offline
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:
Code:
function @FindLotNumber():string
  define(&i, integer, 0)
  define(&res, string, '')

  for(&i, 1, 1, &current.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]
jim3108 Offline
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:

Code:
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:

Code:
&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:

Code:
&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
#40760 - 09/24/12 11:27 AM Re: Help with script [Re: jim3108]
jim3108 Offline
OL Expert

Registered: 04/19/10
Posts: 316
Loc: London, UK
Raphael's solution is infinitely more elegant !

Top
#40761 - 09/24/12 11:38 AM Re: Help with script [Re: jim3108]
tbradley Offline
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, &current.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]
jim3108 Offline
OL Expert

Registered: 04/19/10
Posts: 316
Loc: London, UK
There is a comma missing!

Code:
&res := trim(mid(@(&i, 1, 500), pos('Lot Numbers:' @(&i, 1, 500))+12, 25))


Put the comma after 'Lot Numbers:' and before @

Code:
&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]
tbradley Offline
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
#40764 - 09/24/12 12:14 PM Re: Help with script [Re: tbradley]
jim3108 Offline
OL Expert

Registered: 04/19/10
Posts: 316
Loc: London, UK
No worries smile

Top
Page 1 of 2 1 2 >