Parse a path from comma delimited field?

TGTech

New Member
I am new to progress development. I need to parse a UNC path from field data which was concantenated using commas(",") as delimiters. No matter what i do i cannot seem to get the variable "PosA" to return the position of the first comma. Here is what I thought would work:

DEF VAR ClientFilePath AS CHAR no-undo.
DEF VAR PosA AS INT no-undo.

FIND SysAgent WHERE SysAgent.FileRootDir <> "" No-Lock No-Error.
ClientFilePath = SysAgent.FileRootDir.
PosA = LOOKUP(ClientFilePath, ",").
ClientFilePath = SUBSTRING(ClientFilePath,1,PosA-1).

NOTE: The contents of the field "SysAgent.FileRootDir" are "//server/folder1,c:/folder2,//server/folder2"
NOTE: I changed the backslashes to forwardslashes because the forum editor wanted to see them as paths.
NOTE: I am trying to pull the first path from the field.
NOTE: I also thought I could put the LOOKUP inside the SUBSTRING but it is easier to read as it is.

PosA always returns 0.

Why doesn't this work? Is there a better (working) way?

Thanx in advance!
 
have a look at the "ENTRY" command. The default is to use commas as delimeters.

mystring = entry(1,searchstring).


Ken

Thanx for the response Ken.

As I do not yet have a command reference manual is there a web-based reference I could use to lookup ENTRY??
 
I am new to progress development. I need to parse a UNC path from field data which was concantenated using commas(",") as delimiters. No matter what i do i cannot seem to get the variable "PosA" to return the position of the first comma. Here is what I thought would work:

DEF VAR ClientFilePath AS CHAR no-undo.
DEF VAR PosA AS INT no-undo.

FIND SysAgent WHERE SysAgent.FileRootDir <> "" No-Lock No-Error.
ClientFilePath = SysAgent.FileRootDir.
PosA = LOOKUP(ClientFilePath, ",").

PosA always returns 0.

Why doesn't this work? Is there a better (working) way?

Thanx in advance!

LOOKUP shows the position of a string inside another string. You are looking at a string "," and trying to find another string (clientfilepath) inside it.

If you run the following you will see that the first 2 return 0 and the last one returns 1, because it is looking at a string that contains the search string.

display LOOKUP("1", "").
display LOOKUP("1", ",").
display LOOKUP("1", "1,2,3,4,5").

But, as the others have said, ENTRY is the command to use.

Here are some examples, probably too many, but ....

/* To get the first entry in a list */

display entry (1,"1,2,3,4,5").

/* To get the 5th entry in a list */

display entry (5,"1,2,3,4,5").

/* To get the last entry in a list */

display entry (num-entries("1,2,3,4,5"),"1,2,3,4,5").

/* To get the first entry in a list that uses a different delimiter (.) */

display entry (1,"1.2.3.4.5",".").
display entry (1,"//myserver/mydir/myfile,//myotherserver/myotherdir/myotherfile")
form "x(40)".
display entry (2,"//myserver/mydir/myfile,//myotherserver/myotherdir/myotherfile")
form "x(40)".

def var mylist as char no-undo.
def var myentry as int no-undo.
def var mydelimiter as char initial "/" no-undo.

mylist = "//myserver/mydir/myfile,//myotherserver/myotherdir/myotherfile".
myentry = 1.

/* To get an entry in a list, both of which are variables*/

display entry (myentry,mylist) form "x(40)" entry (myentry + 1 ,mylist) form "x(40)".
display entry (num-entries (entry(1,mylist),"/"),entry(1,mylist),"/").

/* To get an entry in a list using a delimiter, all of which are variables*/

display entry (num-entries (entry(1,mylist),mydelimiter),entry(1,mylist),mydelimiter).





If you are using the standard Windows Progress Editor, then highlight a command in your program, right-click it and choose Keyword help and you get a very detailed and helpful help screen.

If you are using Character-based Progress, there are some manuals at http://www.psdn.com/library/kbcategory.jspa?categoryID=282 and some may even have come with your Progress Installation Disks.
 
If you want to read them out 1 by 1 use something like below:

DEFINE VARIABLE cPath AS CHARACTER NO-UNDO.
DEFINE VARIABLE iNum AS INTEGER NO-UNDO.

ASSIGN cPath = "//server/folder1,c:/folder2,//server/folder2".

/*-------------------------------------------------------------------
With 'NUM-ENTRIES' progress can tell you how many delimeter separated
strings there are.
(in your case delimiter = "," --> default in the ENTRY statement)
-------------------------------------------------------------------*/
DO iNum = 1 TO NUM-ENTRIES(cPath):
DISPLAY ENTRY(iNum, cPath) FORMAT "x(20)".
PAUSE.
END.
 
Back
Top