开发者

Add a second Address line into this custom function (Filemaker Pro)

开发者 https://www.devze.com 2022-12-14 15:12 出处:网络
I want to add a second Address field into this custom function (ie. Apt. #101). If you wanted, you could explain how the Case(not IsEmpty works and I would be willing to attempt to add the second addr

I want to add a second Address field into this custom function (ie. Apt. #101). If you wanted, you could explain how the Case(not IsEmpty works and I would be willing to attempt to add the second address field in myself...

Let(
[
    x1 = Name;
    x2 = x1 & Case开发者_如何学编程(not IsEmpty(Address); Case(not IsEmpty(x1); "¶") & Address);
    x3 = Case(not IsEmpty(City); City & ", ") & Case(not IsEmpty(State); Upper ( State ) & " ") & Zip;
    x4 = x2 & Case(not IsEmpty(x3); "¶") & x3;
    x5 = x4 & Case(not IsEmpty(Country); Case( not IsEmpty(x4); "¶") & Country)
];

    x5

)


Let( [

   x1 = Customer::FullName;
   x2 = x1 & Case(not IsEmpty(Address1); Case(not IsEmpty(x1); "¶") & Address1);
   x3 = x2 & Case(not IsEmpty(Address2); Case(not IsEmpty(x2); "¶") & Address2);
   x4 = Case(not IsEmpty(City); City & ", ") & Case(not IsEmpty(State); Upper ( State ) & " ") & ZipCode;
   x5 = x3 & Case(not IsEmpty(x4); "¶") & x4 ];

x5

)


I'd recommend doing away with the let statement, it seems to make it more confusing. The end goal is, you want to concatenate a bunch of address values together. If an address value is not empty, you want to put a line break (or a comma + space, for the city) after the element in question. Something like this:

LeftWords (
    Case (not IsEmpty(Customer::FullName) ; Customer::FullName & "¶" ) &
    Case (not IsEmpty(Address1) ; Address1 & "¶" ) &
    Case (not IsEmpty(Address2) ; Address2 & "¶" ) &
    Case (not IsEmpty(City) ; City & ", " ) &
    Case (not IsEmpty(State) ; Upper (State ) & " " ) &
    ZipCode
; 9999 )

The LeftWords function with an arg of 9999 (or some other suitably large value) removes any trailing newline or whitespace, which could happen if city, state, and zip are all empty.


Use the List() function:

List( 
 Address Line 1;
 Address Line 2;
 Substitute( List( Sity, Upper( State ); ZIP ); "¶"; " " );
 Country ) )

The idea here is that the List() function ignores empty values, so you don't have to test whether they're empty or not. With address lines it will automatically ignore empties; with sity-state-ZIP line it will give you a valid list and all you have to do is to replace the separator.

If you're using FM Advanced, define a custom function to join a list with a given separator:

/* Join( separator; list *) */
Substitute( list; "¶"; separator )

This will make it simpler.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号