Solved

Formula Field for Address Label

Posted on 2011-09-21
7
249 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
  • 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 100

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 100

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 34

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 34

Expert Comment

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

 James
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now