Code: Select all
private strMonths as StringVectorData({
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" })
public Function MonthName(byval n as byte) as String
MonthName = iif((n>0 and n<13), strMonths(n), "?")
end function
sub main()
dim i as byte
for i= 0 to 14
debug.print (n>0 and n<13); " ";
debug.print MonthName(i)
next
end sub
?
Jan
?
Mar
?
May
?
Jul
?
Sep
?
Nov
?
?
If the (n>0 and n<13) test is executed outside of IIf, however, the behavior is correct:
Code: Select all
private strMonths as StringVectorData({
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" })
public Function MonthName(byval n as byte) as String
dim tf as boolean
tf = (n>0 and n<13)
MonthName = iif(tf, strMonths(n), "?")
end function
sub main()
dim i as byte
for i= 0 to 14
debug.print MonthName(i)
next
end sub
?
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
?
?
as expected.