摘要:#Region "GetRuleList, iGetStat, iGetFuildType, UpdateTypeCheckBox, UpdateStatCheckBox"

"GetRuleList, iGetStat, iGetFuildType, UpdateTypeCheckBox, UpdateStatCheckBox"#Region "GetRuleList, iGetStat, iGetFuildType, UpdateTypeCheckBox, UpdateStatCheckBox"
' Check the CkeckBox base on RuleList 
Public Sub GetRuleList() Sub GetRuleList(ByVal psRule As String, ByRef piRuleList() As Integer)
Try
If psRule = BLANK Then Exit Sub
Dim liRuleALL As Integer = CInt(psRule)
Dim liRuleCount As Integer = 0
Dim liRulePower As Integer = piRuleList.Length
Dim liRuleGroup As Integer
' iRuleALL eg : 2+4+8+16+32+64
' iRulePower eg : 6 . It is because 2^ 6 = 64
' iRuleGroup eg : 2,4,8,16,32,64
' eg : use 1,2,4 to record the checked box, 7 means Checked 3Boxes3
' Loop 1---2---3---4
'---------------------------------
' iRuleALL = 7 > 7 > 3 > 1
' iRulePower = 3 > 2 > 1 > 0
' liRuleGroup = 8 > 4 > 2 > 1
' In Loop 1. 7 < 8 then next
' In Loop 2.as 7>4 , we know that the checked box "4" was checked ,then we put it in RuleList
' and so on.
' Improvement.
' In this task, The Loop 1 is useless. We can reduce the iRulePower 1.
' However it only save O(1) time. For a computer it is nothing at all.
' so I keep it for the higher readability
While liRulePower >= 0
liRuleGroup = CInt(Math.Pow(2, liRulePower))
If liRuleALL >= liRuleGroup Then
piRuleList(liRuleCount) = liRuleGroup
liRuleALL = liRuleALL - liRuleGroup
liRuleCount += 1
End If
liRulePower -= 1
End While
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Sub

Public Function iGetStat() Function iGetStat(ByVal chkA As CheckBox, ByVal chkB As CheckBox) As String
Try
Dim liType As Integer = 0
If chkA.Checked = True Then
liType += 1
End If
If chkB.Checked = True Then
liType += 2
End If
iGetStat = liType
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Function 
Public Function iGetFuildType() Function iGetFuildType(ByVal chkA As CheckBox, ByVal chkB As CheckBox, ByVal chkC As CheckBox) As String
Try
Dim liType As Integer = 0
If chkA.Checked = True Then
liType += 1
End If
If chkB.Checked = True Then
liType += 2
End If
If chkC.Checked = True Then
liType += 4
End If
iGetFuildType = liType
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Function

Public Function UpdateStatCheckBox() Function UpdateStatCheckBox(ByRef chkA As CheckBox, ByRef chkB As CheckBox, ByVal piStatList() As Integer) As String
Try
For liCount As Integer = 0 To piStatList.Length - 1
Select Case piStatList(liCount)
' the checked box Name as 1 was checked
Case 1
chkA.Checked = True
' the checked box Name as 2 was checked
Case 2
chkB.Checked = True
End Select
Next
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Function 
Public Function UpdateTypeCheckBox() Function UpdateTypeCheckBox(ByRef chkA As CheckBox, ByRef chkB As CheckBox, ByRef chkC As CheckBox, ByVal piStatList() As Integer) As String
Try
For liCount As Integer = 0 To piStatList.Length - 1
Select Case piStatList(liCount)
Case 1
chkA.Checked = True
Case 2
chkB.Checked = True
Case 4
chkC.Checked = True
End Select
Next
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Function
#End Region
------------------
熱愛生命 喜愛新奇 有趣的事物
過去 是無法改變
將來 卻能夠創造
希望使大家生活更便利
世界更美好
a guy who loves IT and life