我有一套需要遵守的规则,并且想知道定义一组规则的最佳方法。基本上,有一组if - >然后我会感兴趣,如果有更优雅的编码方式(案例陈述或某种规则集)
规则如下:
这是我的功能:
Public Function EvSystem(dev As Integer, impl As Integer, supp As Integer, refs As Integer) As Integer
Dim score As Integer
score = 0
If dev <= 0 Then
score = 0
Else
If (dev >= 1) And (impl >= 1) And ((refs >= 3) And (refs <= 4)) Then
score = 4
End If
If (dev > 1) And (impl >= 1) And (supp >= 1) And (refs >= 5) Then
score = 5
End If
End If
EvSystem = score
End Function
答案 0 :(得分:1)
如果我正确理解您的描述,您可以将代码简化为以下(未经测试的代码):
Public Function EvSystem(dev As Integer, impl As Integer, supp As Integer, refs As Integer) As Integer
Dim score As Integer
score = 0
If (dev > 0) And (impl > 0) Then
If (refs >= 3) And (refs <= 4) Then
score = 4
End If
If (supp >= 1) And (refs >= 5) Then
score = 5
End If
End If
EvSystem = score
End Function
答案 1 :(得分:1)
Public Function EvSystem(dev As Integer, impl As Integer, supp As Integer, refs As Integer) As Integer
Dim score As Integer
score = -4 * ((dev >= 1) And (impl >= 1) And (refs >= 3)) - ((supp >= 1) And (refs >= 5))
EvSystem = score
End Function