mbdave
25th August 2009, 15:58
Hi Guys,

The On case statement showed me some weird results in baan.
Can anybody throw light on it!

I had written On case statement as

on case temp.str
case tmp.str1:
hold = 1
break
case tmp.str2:
hold = 2
break
endcase

Now if my tmp.str1 and tmp.str2 are equall i.e. say tmp.str1 = tmp.str2 = "ABC"
If input temp.str = "ABC"
then the cursor directly goes to second case i.e it returns hold = 2

Currenctly for this reason i had replaced this "On case" with "IF" statement and its working fine.
Just want to know y its not going to first case.

Hitesh Shah
25th August 2009, 17:59
On case statement may prepare internally array of constants and then may be searching binary mode (in which first written constant does not come first ). And due to that reason only it's claimed to faster that if-the-else iterations . U may try with 3 values also . My guess in that case also it will be 2nd only . As long as it gives consistent results in all cases (like in ur case), it can not be said to weird behavior .

Do some good testing and give feedback.

mark_h
25th August 2009, 22:56
I thought I read somewhere that the case statement would always execute the last statement that it matches. I also believe the case statement was set-up for unique values - never tried something like this. A good test would to be like hitest recommended is to add a third choice where it matches it also. That would give you a better test.

steveauckly
25th August 2009, 23:24
I know if you have constants in the on case instead of variables, it will not compile if they are equal. I would try to avoid this.

mbdave
27th August 2009, 14:52
Hi Guys,

Thanks for ur inputs but when i tried more cases it went to the last.
Hence what mark is saying is right in Baan the On case statemnt searches from the last, atleast in case of Simialr data.