Solved

Formula Field for Address Label

Posted on 2011-09-21
7
284 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can I add a checkbox function/control button in Crystal Reports ? 4 82
Formatting number to Text Format DDDDDDDDCC 1 49
Crystal Reports 12 46
free Crystal Report viewer 4 37
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

740 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