Page 1 of 1

is there a limit to else if statements?

PostPosted: Tue Jan 16, 2018 9:51 pm
by bobm
I have a simple function that hides/shows specific elements (38) based on 38 possible different conditions, so a lengthy else if is needed. When I have 34 of these conditions running the program works fine in both Smart and Web clients.

When I add one more condition then the Smart Client errors (only in production NOT in developer) - the Web client works fine.
The error is "TypeError showDX is not a funtion, it is object."

The partial code below shows one of those conditions.
Code: Select all
function showDx(){

var a = VisionImpairmentDefinitions_OD;
var b = VisionImpairmentDefinitions_OS;
var msgOD = 'You have chosen an Unqualified Vision Loss in the Right Eye. You must select Category 0-Normal- or Category 9-Undetermined- for the Left Eye.'
var msgOS = 'You have chosen an Unqualified Vision Loss in the Left Eye. You must select Category 0-Normal- or Category 9-Undetermined- for the Right Eye.'

if (a == "1" & b == "0"){
      elements.H54511A.visible= true;
      elements.H54512A.visible=false;
      elements.H5452A1.visible=false;
      elements.H5452A2.visible=false;
      elements.H54413A.visible=false;
      elements.H54414A.visible=false;
      elements.H54415A.visible=false;
      elements.H5442A3.visible=false;
      elements.H5442A4.visible=false;
      elements.H5442A5.visible=false;
      elements.H542X11.visible=false;
      elements.H542X12.visible=false;
      elements.H542X21.visible=false;
      elements.H542X22.visible=false;
      elements.H541131.visible=false;
      elements.H541132.visible=false;
      elements.H541141.visible=false;
      elements.H541142.visible=false;
      elements.H541151.visible=false;
      elements.H541152.visible=false;
      elements.H541213.visible=false;
      elements.H541214.visible=false;
      elements.H541215.visible=false;
      elements.H541223.visible=false;
      elements.H541224.visible=false;
      elements.H541225.visible=false;
      elements.H540X33.visible=false;
      elements.H540X34.visible=false;
      elements.H540X35.visible=false;
      elements.H540X43.visible=false;
      elements.H540X44.visible=false;
      elements.H540X45.visible=false;
      elements.H540X53.visible=false;
      elements.H540X54.visible=false;
      elements.H540X55.visible=false;
      elements.H543.visible=false;
      elements.H5461.visible=false;
      elements.H5462.visible=false;

   }else if(a == "2" & b == "0"){  ... 


Thanks for the help,
Bob

Re: is there a limit to else if statements?

PostPosted: Wed Jan 17, 2018 2:38 pm
by jcompagner
If it really is only a smart client problem when in production then it is very likely a compile problem
Because by default the smart client compiles the javascript into java classes. This sometimes fails in certain situations when something gets to complex

You can make your code less complex (divide it up) or disable the compile by pushing a system property (can be configured on the admin page): servoy.disableScriptCompile=true to the smart client
system.property.servoy.disableScriptCompile=true in the system.properties area on the admin page.

Re: is there a limit to else if statements?

PostPosted: Wed Jan 17, 2018 3:10 pm
by bobm
Thanks Johan,
I'll try that tonight.

Re: is there a limit to else if statements?

PostPosted: Fri Nov 01, 2019 4:12 pm
by gdurniak
Thanks for posting this

In my case, it was probably Arrays. It seems Compilers do have limits. I just wish Servoy would throw an error, or fail completely.

My solution ran fine in Developer, but on Server, a Method apparently did not compile, so just ONE button did not work

I had to put a TRY CATCH around the Button's Call, to learn the Method in Smart Client was considered an OBJECT, not a FUNCTION, which led me here

It works now, with Compile Disabled ( thank God for Google ! )

greg

Servoy 7.4.3

Re: is there a limit to else if statements?

PostPosted: Fri Feb 21, 2020 4:30 pm
by palacio
Hi , Thank you for posting this the error that happened to us was easily resolved by this thread.
I would just like to say that it is true putting "system.property.servoy.disableScriptCompile=true" in the system.properties area on the admin page works
but we don't know the impact of the property so the other way is to create another micro function and use it inside your big function because the real problem is that you
have already maximized the allowed if condition (I think :D)

palacio