Labels not working

Questions and answers for designing and implementing forms in Servoy

Labels not working

Postby Thunder » Tue Jul 22, 2003 11:56 pm

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%%<br>
%%address_1%%<br>
%%address_2%%<br>
%%address_3%%<br>
%%city%%<br>
%%county%%<br>
%%postcode%%<br>
%%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
Thunder
 
Posts: 431
Joined: Thu Apr 24, 2003 10:33 am
Location: London

Postby sebster » Wed Jul 23, 2003 7:17 am

I think something like this might be what you want:

Code: Select all
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 + "<br>";
}

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

return label;
sebster
 
Posts: 251
Joined: Thu Apr 24, 2003 10:03 am
Location: Utrecht, The Netherlands

thank you

Postby Thunder » Thu Jul 24, 2003 1:20 am

thank you thank you thank you thank you thank you

Works a treat.
Thunder
 
Posts: 431
Joined: Thu Apr 24, 2003 10:33 am
Location: London


Return to Forms

Who is online

Users browsing this forum: No registered users and 28 guests