Solved

Formula Field for Address Label

Posted on 2011-09-21
7
296 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:pgkdavefdd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 5

Expert Comment

by:Eduardo Goicovich
ID: 36578113
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;



0
 
LVL 101

Expert Comment

by:mlmcc
ID: 36578195
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
0
 
LVL 5

Expert Comment

by:Eduardo Goicovich
ID: 36580927
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;

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 101

Expert Comment

by:mlmcc
ID: 36581111
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
0
 
LVL 35

Accepted Solution

by:
James0628 earned 500 total points
ID: 36588012
mlmcc is correct about needing to test for nulls first, but he left your length > 3 test out of his formula.  You could combine the IsNull and length tests (to simplify the formula slightly).

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


 James
0
 

Author Closing Comment

by:pgkdavefdd
ID: 36596084
This works great!  Thansk you for your help!
0
 
LVL 35

Expert Comment

by:James0628
ID: 36596754
You're welcome.  Glad I could help.

 James
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question