how to display a field based on a condition

How can I display a Field based on a condition?

Ex. Table name Banks with field DEPOSIT AND DISBURS

I want to display only the field that has a value

DEPOSIT or DISBURS

if try the following Events onInit

if ({DEPOSIT} <> 0)
{
sc_field_display({DISBURS},off);
}
else
{
sc_field_display({DEPOSIT},off);

but go an error message that I cannot identify

Parse error: syntax error, unexpected ‘;’, expecting T_FUNCTION in C:Program Files
etmakev5wwwrootscriptcaseappecogazform_banks_1form_banks_1_apl.php on line 4192

Please assist me!

Re: how to display a field based on a condition

try if changing:
sc_field_display({DISBURS},off);

to

sc_field_display({DISBURS},‘off’);

Also, not sure if it a paste error, but you have no closing bracket on your ‘else’

Regards,
Scott.

Re: how to display a field based on a condition

Ok I put the quote - I am not getting the expected result

Only 1 of the field can be displayed not both

[b]as an xBase programmer ,

I would write the code like this[/b]
if BANKS->deposit <> 0

display label "Deposit: "

display value found in deposit field example -> 134,035.85

else

display label “Disbursement”

display value found in BANKS->disburs field

How can I realize this in SC

Re: how to display a field based on a condition

Try moving your code to onLoad. I think there are no values yet to compare in your fields in onInit.

Regards,
Scott.

Re: how to display a field based on a condition

As Scott said, you should write your code in OnLoad Event

Re: how to display a field based on a condition

Yes indeed, ScottMartin, I moved the code to onLoad and it work but only for deposits
I think since the fields are displayed as default - you need some code to handle the other fields which is DISBURS

I manage to make it work as needed with the following code:

if ({DEPOSIT} <> 0)
{
sc_field_display({DEPOSIT},‘on’);
sc_field_display({DISBURS},‘off’);
}
else
{
sc_field_display({DISBURS},‘on’);

}

if ({DISBURS} <> 0)
{
sc_field_display({DISBURS},‘on’);
sc_field_display({DEPOSIT},‘off’);
}
else
{
sc_field_display({DEPOSIT},‘on’);

}

If there is a better way to do it please share

Thanks again for your support

Re: how to display a field based on a condition

Perhaps something like:

untested:


{DEPOSIT} <> 0 ? $deposit_display = 'on' : $deposit_display = 'off';
{DISBURS} <> 0 ? $disburs_display = 'on' : $disburs_display = 'off'; 

sc_field_display({DEPOSIT},$deposit_display);
sc_field_display({DISBURS},$disburs_display);

Regards,
Scott.

Re: how to display a field based on a condition

Re: how to display a field based on a condition

The logic is there, per echo checks, the problem is that sc_field_display() requires a constant of “on”,“off” and it you send it as a var as I have it does not work. I even tried placing quotes in the string var, but it does not work. I even tried to define a constant.

It would be nice of the 2nd argument was a 1,0 or TRUE/FALSE instead of “on”,“off”. Not sure what the thought was here.

Perhaps I can persuade NetMake to make this change, or perhaps there is another method to pass a constant I am not thinking of.

Regards,
Scott.