#include <array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2_1 = GUICreate("分别组合计算和、反向计算", 356, 318, -1, -1)
$Group1 = GUICtrlCreateGroup("单选项", 10, 10, 130, 105)
$Radio1 = GUICtrlCreateRadio("1", 20, 35, 110, 17)
$Radio2 = GUICtrlCreateRadio("2", 20, 60, 110, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio3 = GUICtrlCreateRadio("4", 20, 85, 110, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("多选项", 10, 130, 130, 175)
$Checkbox1 = GUICtrlCreateCheckbox("8", 20, 155, 100, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Checkbox2 = GUICtrlCreateCheckbox("16", 20, 179, 100, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Checkbox3 = GUICtrlCreateCheckbox("32", 20, 203, 100, 17)
$Checkbox4 = GUICtrlCreateCheckbox("64", 20, 227, 100, 17)
$Checkbox5 = GUICtrlCreateCheckbox("128", 20, 251, 100, 17)
$Checkbox6 = GUICtrlCreateCheckbox("1024", 20, 275, 100, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label1 = GUICtrlCreateLabel("计算的结果:", 150, 17, 76, 17)
$Input1 = GUICtrlCreateInput("26", 225, 15, 120, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
GUICtrlSetTip(-1, "输入一个整数来反计算")
$Button1 = GUICtrlCreateButton("选项合计", 150, 40, 90, 25)
$Button2 = GUICtrlCreateButton("反计算", 255, 40, 90, 25)
$Label2 = GUICtrlCreateLabel("单选项结果:", 150, 72, 76, 17)
$Input2 = GUICtrlCreateInput("2", 225, 70, 120, 21)
$Label3 = GUICtrlCreateLabel("多选项结果:", 150, 97, 76, 17)
$Input3 = GUICtrlCreateInput("8、16", 225, 95, 120, 21)
$Button4 = GUICtrlCreateButton("检测", 150, 125, 75, 25)
GUICtrlSetTip(-1, "检测结果是否用到单选项来计算")
$Label4 = GUICtrlCreateLabel("检测计算结果项是否用到单选项来计算。", 230, 125, 116, 27)
$Button3 = GUICtrlCreateButton("组合计算和", 150, 165, 75, 25)
$Label4 = GUICtrlCreateLabel("选择项分别组合计算和。", 230, 165, 116, 27)
$Edit1 = GUICtrlCreateEdit("", 150, 195, 195, 110, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $Radio = 2
While 1
Local $nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Radio1
$Radio = 1
Case $Radio2
$Radio = 2
Case $Radio3
$Radio = 4
Case $Button1
Local $sFlag = _SetFlag()
GUICtrlSetData($Input1, $sFlag)
Case $Button2
Local $nn = GUICtrlRead($Input1)
Local $sFlag0 = _Js($nn)
Local $result = StringInStr($sFlag0, "、")
GUICtrlSetData($Input2, StringLeft($sFlag0, $result - 1))
GUICtrlSetData($Input3, StringMid($sFlag0, $result + 1))
Case $Button3
GUICtrlSetData($Edit1, _SUM())
Case $Button4
If BitAND(GUICtrlRead($Input1), $Radio) Then
MsgBox(4096, "提示", GUICtrlRead($Input1) & " 是用到 " & $Radio & " 计算")
Else
MsgBox(4096, "提示", GUICtrlRead($Input1) & " 否用到 " & $Radio & " 计算")
EndIf
EndSwitch
WEnd
Func _SetFlag()
Local $iFlag = 0
;单选项
Select
Case GUICtrlRead($Radio1) = $GUI_CHECKED
$iFlag = $iFlag + 1
Case GUICtrlRead($Radio2) = $GUI_CHECKED
$iFlag = $iFlag + 2
Case GUICtrlRead($Radio3) = $GUI_CHECKED
$iFlag = $iFlag + 4
EndSelect
;多选项
If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then $iFlag = $iFlag + 8
If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then $iFlag = $iFlag + 16
If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then $iFlag = $iFlag + 32
If GUICtrlRead($Checkbox4) = $GUI_CHECKED Then $iFlag = $iFlag + 64
If GUICtrlRead($Checkbox5) = $GUI_CHECKED Then $iFlag = $iFlag + 128
If GUICtrlRead($Checkbox6) = $GUI_CHECKED Then $iFlag = $iFlag + 1024
Return $iFlag
EndFunc ;==>_SetFlag
Func _Js($nn)
Local $sOut = ''
Local $aN[9] = [1, 2, 4, 8, 16, 32, 64, 128, 1024]
For $ii = 0 To UBound($aN) - 1
If BitAND($nn, $aN[$ii]) Then $sOut &= $aN[$ii] & '、'
Next
Return StringTrimRight($sOut, 1)
EndFunc ;==>_Js
Func _SUM()
Local $iFlag
;单选项
Select
Case GUICtrlRead($Radio1) = $GUI_CHECKED
$iFlag = $iFlag & "1,"
Case GUICtrlRead($Radio2) = $GUI_CHECKED
$iFlag = $iFlag & "2,"
Case GUICtrlRead($Radio3) = $GUI_CHECKED
$iFlag = $iFlag & "4,"
EndSelect
;多选项
If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then $iFlag = $iFlag & "8,"
If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then $iFlag = $iFlag & "16,"
If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then $iFlag = $iFlag & "32,"
If GUICtrlRead($Checkbox4) = $GUI_CHECKED Then $iFlag = $iFlag & "64,"
If GUICtrlRead($Checkbox5) = $GUI_CHECKED Then $iFlag = $iFlag & "128,"
If GUICtrlRead($Checkbox6) = $GUI_CHECKED Then $iFlag = $iFlag & "1024,"
$iFlag = StringTrimRight($iFlag, 1)
$aN = StringSplit($iFlag, ",", 2)
Local $aArrayTarget[1]
For $ii = 2 To UBound($aN)
Local $aNCombo = _ArrayCombinations($aN, $ii, '+')
For $jj = 1 To $aNCombo[0]
$aNCombo[$jj] = $aNCombo[$jj] & '=' & Execute($aNCombo[$jj])
;$aNCombo[$jj] = Execute($aNCombo[$jj])
Next
_ArrayDelete($aNCombo, 0)
_ArrayConcatenate($aArrayTarget, $aNCombo)
Next
;_ArrayDisplay($aArrayTarget)
_ArrayDelete($aArrayTarget, 0)
Return _ArrayToString($aArrayTarget, @CRLF)
EndFunc ;==>_SUM