看板 Visual_Basic 關於我們 聯絡資訊
MOONRAKER:對,iif既為函數,那麼每個參數都要在傳進函數前先算完 04/23 16:57
MOONRAKER:而這一算之下,會錯的當然就先signal error了 04/23 16:57
M大說的很對 原po可以看一下MS msdn裡的說明 http://msdn.microsoft.com/en-us/library/27ydhh0d(VS.71).aspx Note The expressions in the argument list can include function calls. As part of preparing the argument list for the call to IIf, the Visual Basic compiler calls every function in every expression. This means that you cannot rely on a particular function not being called if the other argument is selected by Expression. VB compiler 會先把每一個傳入參數編譯過,所以在這情況下, 雖然第一種敘述方式看樣子好像是有排除分母為零的狀況,但實際上, compiler都會try兩種狀況,因而造成除以零的溢位。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.117.177.29 ※ 編輯: IamCoolKing 來自: 59.117.177.29 (04/24 15:59)