Labels not working

I have been struggling to figure this out by myself all day but must now defer to the forum. Annoyingly I know that it is going to be very simple for someone out there.

I am trying to make a printable label on a form in Servoy.
If I use merge fields:

%%title%% %%first_name%% %%last_name%%

%%address_1%%

%%address_2%%

%%address_3%%

%%city%%

%%county%%

%%postcode%%

%%country%%

it works, but I get blank lines wherever there is an empty field.

If I try to make the label as the result of a calculation, I am unable to figure out the syntax, the closest I have got (I think) is:
return
if (title != null && title != “” )
{
return title
}
else
{
return “”
}
if (first_name != null && first_name != “”)
{
return first_name + " "
}
else
{
return “”
}
if (last_name != null && last_name != “”)
{
return last_name + " ";
}

The problem with this is that it only returns the first evaluation. I cannot find a way to join them together (+ & . etc. don’t work)

I am guessing that I have to nest the if statements but this doesn’t seem to work either (because I keep getting syntax errors). I have read the manual cover to cover and tried to find syntax examples for doing this and simply cannot.

I would be very grateful if anyone can point me at the right literature, and or give me a hint about which way to actually do this.

Many thanks for your time.

Bevil

I think something like this might be what you want:

var label = "";

if (title || first_name || last_name)
{
    if (title)
        label = label + title + " ";
    if (first_name)
        label = label + first_name + " ";
    if (last_name)
        label = label + last_name;
    label = label + "
";
}

if (address_1)
    label = label + address_1 + "
";
if (address_2)
    label = label + address_2 + "
";
// etc

return label;

thank you thank you thank you thank you thank you

Works a treat.