The Switch statement is not evaluating numerical data (integer or float) properly, but does evaluate string data correctly. When evaluating numerical data, it falls through all the cases until it hits the ‘default’ and executes the default code.
What is disturbing is that this has been noted on the Servoy forum since 2006…egads! Search criteria: switch statement not working.
Try the following code (one example is numeric, the other text - one works, the other does not):
var answer = 1 ;
answer = plugins.dialogs.showInputDialog( “Get Answer” , “N”, answer );
switch( answer )
{
case 1.0 : ;
plugins.dialogs.showInfoDialog( ‘Test Switch N - 1’, answer, answer );
break;
case 2.0 : ;
plugins.dialogs.showInfoDialog( ‘Test Switch N - 2’, answer, answer );
break;
case 4.0 : ;
plugins.dialogs.showInfoDialog( ‘Test Switch N - 4’, answer, answer );
break;
default:
plugins.dialogs.showInfoDialog( ‘Test Switch N - Default’, answer, answer );
}
// -------------------------------------------------------------
var answer = “What” ;
answer = plugins.dialogs.showInputDialog( “Get Answer” , “A”, answer );
switch( answer )
{
case “Save”: ;
{
plugins.dialogs.showInfoDialog( ‘Test Switch A - Save’, answer, answer );
// break;
}
case “WhatEver”: ;
{
plugins.dialogs.showInfoDialog( ‘Test Switch A - WhatEver’, answer, answer );
break;
}
case “What”: ;
{
plugins.dialogs.showInfoDialog( ‘Test Switch A - What’, answer, answer );
break;
}
default:
plugins.dialogs.showInfoDialog( ‘Test Switch A - Default’, answer, answer );
}
We know that we can work around this using ‘if, else if’ clauses, but wanted to bring this to your attention. This is a rather severe bug, and we can’t tell if this is a Servoy issue or JVM issue.
We are using Servoy Developer 3.5.5 on Windows XP and Vista.