有人可以帮我解决这个问题吗。这个函数的目的应该是从数据库中获取值并更改名称,如
存款,提款,手动余额更正,现金更正,HighRoller存款更正,HighRoller撤销更正,玩家发送,玩家接收,现金存款,现金提取,提示存款,提示提款。数据库中的原始表是
Id Name IsCredit
1 Deposit 0
2. Withdrawal 0
3. Manual Balance Correction 0
4. Cash Correction 0
5. HighRoller Correction 0 or 1
6. Player To Player 0 or 1
7. Cash In Cash Out 0 or 1
15. Tip 0 or 1
Function GetTransactionTypeName(ByVal key As Integer, ByVal isCredit As Boolean) As String
Dim keys As Integer() = {1,2,3,4,5,6,7,15}
Dim names As String() = {"Deposit", "Withdrawal", "Manual Balance Correction", "Cash Correction", "High Roller {0} Correction", _
"Player To Player {0}", "Cash In Cash Out {0}", "Tip {0}"}
Dim indx As Integer
For indx = 0 To Ubound(keys)
If keys(indx) = key Then
Exit For
End If
Next
If indx >= Ubound(names) Then
Return key
End If
If key=7 Or key=5 Or Key=6 or Key=15 Then
If isCredit Then
If key=7 Or key=5 Or key=15
Return [String].Format(names(indx) ," Deposit")
End If
If key=6
Return [String].Format(names(indx) ," Recieve")
End If
Else
If key=7 Or key=5 or key=15
Return [String].Format(names(indx) ," Withdrawal")
End If
If key=6
Return [String].Format(names(indx) ," Send")
End If
End If
End If
Return names(indx)
End Function
答案 0 :(得分:1)
为什么不简单地使用SELECT CASE
声明?
Function GetTransactionTypeName(ByVal key As Integer, ByVal isCredit As Boolean) As String
Select Case key
Case 1
Return "Deposit"
Case 2
Return "Withdraval"
...
Case 15
If isCredit Then
"Tip In"
Else
"Tip Out"
End If
Case Else
Return "(Unknown)"
End Select
End Function
它更易于阅读和维护,而且由于您只有8个不同的键值,我敢打赌,完整的代码将比原始代码更短。