Link to home
Start Free TrialLog in
Avatar of pgkdavefdd
pgkdavefddFlag for United States of America

asked on

Formula Field for Address Label

I am trying to write a formula field that would display one address line if only Address Line One has value assigned in the database and  two address lines if both address lines have values.

Here is the code I am using but it does not display the 2nd address:

dim x as string
if len({CWVMembers.Addr2})>3 then
    x = trim({CWVMembers.Addr1}) + Chr(13)+ {CWVMembers.Addr2}
elseif isnull({CWVMembers.Addr2}) = true then
    x = trim({CWVMembers.Addr1})
else
    x = trim({CWVMembers.Addr1})
end if
formula = x

Please advise whatI need to do to correct this.
Avatar of Eduardo Goicovich
Eduardo Goicovich
Flag of Chile image

stringVar varAddress1:=trim("aaaaaaaaaaa");
stringVar varAddress2:=chr(0);

if varAddress2=chr(0)  then
 varAddress2:=""
else
 varAddress2:=trim(varAddress2);

if len(varAddress2)>0 then
  varAddress2:=chr(13) + varAddress2;

varAddress1 + varAddress2;



Avatar of Mike McCracken
Mike McCracken

If  field can be NULL then you need to test for the NULL condition first

dim x as string
if isnull({CWVMembers.Addr2}) = true then
    x = trim({CWVMembers.Addr1})
else
    x = trim({CWVMembers.Addr1}) + Chr(13)+ {CWVMembers.Addr2}
end if
formula = x

mlmcc
using fields from your datasource definition

stringVar varAddress1:={CWVMembers.Addr1} ;
stringVar varAddress2:={CWVMembers.Addr2};

if varAddress2=chr(0)  then
 varAddress2:=""
else
 varAddress2:=trim(varAddress2);

if len(varAddress2)>0 then
  varAddress2:=chr(13) + varAddress2;

varAddress1 + varAddress2;

If the field can be NULL the only test that will succeed on it is IsNull.  All other tests will fail and the formula will terminate execution.  In Crystal NULL is lack of a value not the empty string or the chr(0) string.

mlmcc
ASKER CERTIFIED SOLUTION
Avatar of James0628
James0628

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pgkdavefdd

ASKER

This works great!  Thansk you for your help!
You're welcome.  Glad I could help.

 James