#37960 - 12/06/11 10:02 AM
Re: split Variable Address String from one line
[Re: Ziggy]
|
OL Expert
Registered: 10/14/05
Posts: 4956
Loc: Objectif Lune Montreal
|
Ziggy, If we just wanted to display each values on it's own line, then a simple "search" loop would be enough. However, in this case, we may want some values to be on the same line, and we need to be able to format them more freely. For this case, here's a function that I've made that could help you:
function @ExtractData(&line:integer, &fieldnum:integer):string
% Function to extract data from fields of a csv file. (or any comma delimited files)
% Made by: Raphaël Lalonde Lefebvre, Objectif Lune
% Note that this function is not part of an official solution, and is not supported
% by Objectif Lune. Use this function at your own risks.
define(&i, integer, 0)
define(&pos, integer, 1)
define(&curstr, string, '')
define(&curline, string, '')
define(&inquotes, boolean, false)
define(&j, integer, 0)
&curline := @(&line, 1, 1000)
for(&j, 1, 1, 100)
&curline := stringreplace(&curline, ',,', ', ,')
endfor()
repeat
&curstr := ''
repeat
&curstr := &curstr + mid(&curline, &pos, 1)
if(mid(&curline, &pos, 1) = '"')
if(&inquotes)
&inquotes := False
elseif()
&inquotes := True
endif()
endif()
&pos := &pos + 1
until(((mid(&curline, &pos, 1) = ',') or (&pos > length(&curline))) and (not(&inquotes)))
&i := &i + 1
&pos := &pos + 1
until(&i = &fieldnum)
&Result := stringreplace(&curstr, '"', '')
endfunction()
This function looks at a specific line, and returns the value of a "field". It was originally made for using CSV files in line printer emulation, but it can be used in non-CSV files that still have values separated by commas. The function has two parameters. The first one is the line where the comma-separated values are found. The second one is which value you want. So as a an example, let's assume you have your line of data on data line 3. Knowing this, if you called the function with these parameters: @ExtractData(3, 2) It would return the "second field", in other words, Street Name. If you used this instead: @ExtractData(3, 5) It would return Country. So you could make a text box with some custom variables, and then have each variables make a call to the function. You'll be able to either put a value on each lines, or multiple values on the same line, as you need. Hope that helps! Regards, Raphaël Lalonde Lefebvre
Edited by Raphael Lalonde Lefebvre (12/06/11 10:03 AM)
|
Top
|
|
|
|
#37961 - 12/06/11 10:33 AM
Re: split Variable Address String from one line
[Re: Raphael Lalonde Lefebvre]
|
OL Newbie
Registered: 11/29/11
Posts: 8
|
Thank you very much Raphael, I look forward to trying this shortly. I will let you know how it goes.
The logic sounds like what I am looking for, I Used Monarch sofware in the past and it has functions that let you define a separator and how many "Parts" the string contains... then you specify which part to return.
|
Top
|
|
|
|
#37978 - 12/07/11 09:46 AM
Re: split Variable Address String from one line
[Re: Ziggy]
|
OL Newbie
Registered: 11/29/11
Posts: 8
|
My document is working great, thanks for the help. For any other newbies (like me) wondering where to put the code.. I used the "Press Talk" button then pasted the above code in the "Planet Press Talk code" section ( the dialogue that comes up).... click ok, and I named the object "Extractfunction" (for visual reference)... Note that this is within the Page itselfNOte I also modified the reference slightly because I wanted to capture the data starting/ending at a certain point in the line. from: &curline := @(&line, 1, 1000) to: &curline := @(&line, 14, 91) then I added another "PressTalk" and this is the one that will show the data... I put... showleft(trim(@ExtractData(26, 1))) which refers to the 26 line on my report and the 1st position (field) of the comma separated line., change the 1 to refer to subsequent fields in additioanl "Press Talk" fields to get the other references. That's how I did it, I am sure there might be other variations that will work
Edited by Ziggy (12/07/11 09:59 AM)
|
Top
|
|
|
|
|
|