Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting string formula 2

Status
Not open for further replies.

Buckaroo8

Programmer
Aug 6, 2003
27
US
Hi All,
I have a field which contains strings of letters and/or numbers:
Examples: Hospital-Unit-Room-BedNum or Hospital-Department
Hospital-ICU-1234-1
Hospital-ICU-1234-2
Hospital-TELE-4567-A
Hospital-TELE-4567-A
Hospital-Laboratory

What I need is to have only the last six characters display IF there are numbers in the string - Right({table.field},6)?
AND
if the string has no numbers, display the entire string - Hospital-Department.

Thanks for All Help!
 
if left(Right({table.field},6)) in [0,1,2,3,4,5,6,7,8,9] then
Right({table.field},6)
else
{table.field}
 
Here is the debugged version:

if left(Right({table.field},6),1) in ["0","1","2","3","4","5","6","7","8","9"] then
Right({table.field},6)
else
{table.field}

 
Try:

if isnumber(Right({table.field},1) then
Right({table.field},6)
else
{table.field}

This assumes that if the last character is a number, then all 5 of the 6 characters are.

You could also use a version of kcushing's post to do check the other side:

if isnumber(left(Right({table.field},6),1)
and
isnumber(Right({table.field},1)) then
Right({table.field},6)
else
{table.field}

Otherwise you'd have to loop through the string.

-k
 
Try this:
Code:
stringVar array strRight := split(right({table.field},6),"-");

if isnumeric(strRight[1]) or isnumeric(strRight [ubound(strRight)]) then 
    right(strRight,6)
else
    strRight

~Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top