How to use typeof(clr) in switch statement

May 14, 2010 at 5:31 PM
Edited May 17, 2010 at 5:15 PM
I have a function in my C# app that returns an int to javascript. The int value it returns has a typeof(clr) in javascript. I am having trouble with a switch() statement in the java script; it always falls through to the default code, even when the switch variable has a value that should match a case: statement. If I initialize a numeric variable and use it in the switch() statement, it works fine. Is there something about how a number is represented a typeof(clr) variable that means I need to do something different in a seitch() statemtne?
May 14, 2010 at 6:08 PM
I have a function in my C# app that returns an int to javascript. The int value it returns has a typeof(clr) in javascript. A switch() statement in the java script always falls through to the default code, even when the switch variable has a value that should match a case: statement. patternID = ScannerPatternNumber(handle); switch (patternID) { case 0: ShowMessage("Pattern #0"); break; case 1: ShowMessage("Pattern #1"); break; default: ShowMessage("No patterns matched"); } The ScannerPatternNumber function looks like this: //----------------------------------------------------------------------------------------------- public int ScannerPatternNumber(int handle) //----------------------------------------------------------------------------------------------- { if (scanner != null) return scanner.PatternNumber(handle); else return -1; } I can see in my testing that patternID has a value of 1 but the switch statement executes the code in the default: section. If I hard-code patternID to 1, it displays with a typeof(number) and the switch statement works fine. Is there a way to have the int returned from the ScannerPatternNumber function to be typeof(number) in the javascript enviromnent?