I think there is a bug in the plugin language regarding the switch statement. I am calling a method to convert decimal numbers to roman.
switch (pNumber)
{
case "1"
{
positionRoman = "I";
}
case "10"
{
positionRoman = "X";
}
}
I have missed out the intervening numbers for brevity.
When pNumber is "10" the above switch statement returns "I" when it should return "X". It would seems that the switch statement is not matching the whole string, but the first character when it matches.
I have found the workaround is as follows, proving my point.
switch (pNumber)
{
case "10"
{
positionRoman = "X";
}
case "1"
{
positionRoman = "I";
}
}
Tony - you should probably sign up for the plugin-dev list and ask ManuScript questions there, since they are really not of interest to most people using this list.
The problem is known. There is a thread about it from 2010, where this was part of my response:
*********************************
I am not sure it works with cases, but in some situations I have set up comparisons so that substrings of a longer strings are always compared after the longer string is tested - this is consistent with what you are showing below.
You can sort an array in reverse order, for example, and then use
utils.getArrayIndex to find a string.
I am not positive, but I think the problems only occur when you have a
single character literal. These are internally of type "char" and not
"string". CharAt also produce a char. I have often wished that data type were gone. I see no advantage for it and it causes trouble.
I often do something like
str = "" & str:
if it is possible to be called with a literal that may be a single
character. That forces str to be of type string.
**********************************************************
I do think that the problem only happens if single character literals are involved. It is, of course a problem to have comparisons return the wrong result, but it is been like this from the start and is not likely to be changed. Kind of like the way expressions are evaluated from left to right with no priority, so you always need to parenthesize anything complex. Or like the fact that an array always returns an address rather than a value, so you can't say