Post-Admin:
Date: 2006年 12月 07日
Subject:
ExcelのAND,OR,IFの引数の評価はどうなっているのか
Dim tmp
Function chk1()
tmp = 1
chk1 = True
End Function
Function chk2()
tmp = 2
chk2 = False
End Function
Function chk3()
tmp = 3
chk3 = True
End Function
Function readtmp()
readtmp = tmp
End Function
=IF(AND(chk1(),chk2(),chk3()),readtmp(),readtmp())
=IF(OR(chk1(),chk2(),chk3()),readtmp(),readtmp())
=IF(TRUE,chk1(),chk2())*0+readtmp()
=IF(FALSE,chk1(),chk2())*0+readtmp()
とすると
3
3
1
2
となる。AND,ORとも全ての引数を順に評価し、IFは第一引数によって評価を変えるっぽい。