再會,
我制作了一個程式,在繼續之前有幾個先決條件,并撰寫了一個評分系統來計算是否滿足所有標準,而不需要幾個 if 陳述句。
此外,如果不滿足標準,我會繼續撰寫 if 陳述句來提醒問題,但這也對 if a 或 b 或 c 或 d 變得瘋狂。. . 陳述有沒有更快的數學方法來總結這一點?在某些情況下,我有 6 或 7 個先決條件,有沒有辦法可以將余數或十進制數計算為二進制數?
這是我的意思的一個虛擬示例
dim points as integer
points = 0
if len(range("A1") ) = 6 then points = points 1 'example checks length
if Cdbl(range("B1") ) >= Cdbl(Date) then points = points 2 'example checks if date is in future
if not isempty(range("C1")) then points = points 4 'example checks field is not blank
if points = 7 then
[do some code]
msgbox "criteria met"
else
' this is what I want summarized with 1 nice mathematical equation
if points = 1 or points = 3 or points = 5 or points = 7 then
msgbox "problem is A1"
end if
if points = 2 or points = 3 or points = 6 or points = 7 then
msgbox "problem is B1"
end if
if points = 4 or points = 5 or points = 6 or points = 7 then
msgbox "problem is C1"
end if
end if
uj5u.com熱心網友回復:
是的。你只需要使用And. 如果是奇數,points And 1則將回傳1(相當于以true這種方式使用)points。
points And 6 如果二進制數以 110 或 111 結尾,則回傳 6。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/370747.html
