16,555
社区成员
发帖
与我相关
我的任务
分享
Public Class Form1
Const b As Integer = 1
Const c As Integer = 2
Public Function Status(ByVal CompStat As Integer) As String
' This function interprets a status variable and returns a string
If ((CompStat And b) = b) Then
Status = "Success"
ElseIf ((CompStat And c) = c) Then
Status = "Errors"
Else
Return "others"
End If
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox(Status(561)) ' "Success"
MsgBox(Status(77)) ' "Success"
MsgBox(Status(562)) '"Errors"
MsgBox(Status(888)) '"others"
End Sub
End Class
If ((CompStat And 1) = 1) Then '奇数,之前说了
Return 1
ElseIf ((CompStat And 32) = 32) Then '32=0x100000 除64余32以上?
Return 2 '
ElseIf ((CompStat And 4) = 4) Then '4=0x100 除8余4以上?后面几个以此类推,感觉太复杂了,用十进制很难说出什么意义
'我感觉像在处理一条状态数据或者报警数据,二进制每位代表不同的含义并有不同的优先级(根据elseif的顺序),比如末位如果是1则优先报err1,第六位是1且末位为0才报err2之类的,总之应该和业务挂钩吧,要理解含义应该先看CompStat是怎么来的
Return 3 '
ElseIf ((CompStat And 2) = 2) Then '2=0x10
Return 4 '
ElseIf ((CompStat And 16) = 16) Then '16=0x10000
Return 5
ElseIf ((CompStat And 8) = 8) Then '8=0x1000
Return 6
Else
Return 7
End If