Solved

Formula Field for Address Label

Posted on 2011-09-21
7
290 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 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
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 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 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

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. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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