PARAMETERS tcName IF PCOUNT()=0 lcRefDocName=["ANDERSON IV, HENRY"] ELSE lcRefDocName=tcName ENDIF LOCAL lcReturn,lcLast,lcFirst,mi,lnLen lcRefDocName=ALLTRIM(lcRefDocName) lnlen=LEN(lcRefDocName) *********************************************** * they've put a comma at the end of some of * the name, we need to remove that *********************************************** IF RIGHT(lcRefDocName,1)=[,] lcRefDocName=SUBSTR(lcRefDocName,1,lnLen-1) ENDIF *********************************************** * Determine the comma for where the last name * ends *********************************************** lnComma=ATC(',',lcRefDocName) *********************************************** * If there is a comma now, it should represent * the split betwen the lastname and firstname ************************************************ IF lnComma>0 lcLastName=SUBSTR(lcRefDocName,1,lnComma-1) *************************************************** * Determine if there is a space after the comma *************************************************** lcCharAfterComma=SUBSTR(lcRefDocName,lnComma+1,1) IF lcCharAfterComma=" " lnSecondSpace=ATC(' ',lcRefDocName,2) ELSE lnSecondSpace=ATC(' ',lcRefDocName,1) ENDIF IF lnSecondSpace=0 lnSecondSpace=15 ENDIF lnFirstStartsAt=lnComma+1 lnFirstEndsAt =lnSecondSpace lnDis=lnFirstEndsAt-lnFirstStartsAt lcFirstName=SUBSTR(lcRefDocName,lnFirstStartsAt,lnDis) lcFirstName=ALLTRIM(lcFirstName) lcMi=SUBSTR(lcRefDocName,lnSecondSpace+1,5) lcMI=ALLTRIM(lcMI) lcMI=SUBSTR(lcMI,1,1) lcReturn=[|]+lcLastName+[|]+lcFirstName+[|]+lcMI+[|] ELSE IF ATC(' ',lcRefDocName,1)>0 lnFirstEndsAt=ATC(' ',lcRefDocName,1) * there are at least two words lcLastName=SUBSTR(lcRefDocName,1,ATC(' ',lcRefDocName,1)) lnSecondSpaceAt=ATC(' ',lcRefDocName,2) IF lnSecondSpaceAt>0 lndiff=lnSecondSpaceAt-lnFirstEndsAt lcFirstName=SUBSTR(lcRefDocName,ATC(' ',lcRefDocName,1)+1,lnDiff) ** ToDo - Figure out if there is a midddle lcMi=[] ELSE lcFirstname=[] lcMI=[] ENDIF lcReturn=[|]+lcLastName+[|]+lcFirstName+[|]+lcMI+[|] ELSE lcFirstname=[] lcReturn=[|]+lcRefDocname+[|]+lcFirstName+[|]+[ |] ENDIF ENDIF RETURN (lcReturn)