求算相加和相减的算法
本帖最后由 coocare01 于 2010-12-7 18:35 编辑选中复选框,然后把数据显示到下面,取消也应的减去数据,请高手帮忙
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 316, 216, 192, 114)
Local $a1,$b,$C
$a1 = "150 MB"
$b = "300 MB"
$C = "500 MB"
$Checkbox1 = GUICtrlCreateCheckbox($a1, 72, 24, 105, 25)
$Checkbox2 = GUICtrlCreateCheckbox($b, 72, 64, 105, 25)
$Checkbox3 = GUICtrlCreateCheckbox($C, 72, 104, 105, 25)
$Label1 = GUICtrlCreateLabel("0 MB", 216, 160, 52, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd 本帖最后由 tryhi 于 2010-12-7 19:06 编辑
回复 1# coocare01
如果有帮到你的话,楼主能不能帮我加4点贡献,我加你50个金钱#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 316, 216, 192, 114)
Local $a1,$b,$C
$a1 = "150 MB"
$b = "300 MB"
$C = "500 MB"
$Checkbox1 = GUICtrlCreateCheckbox($a1, 72, 24, 105, 25)
$Checkbox2 = GUICtrlCreateCheckbox($b, 72, 64, 105, 25)
$Checkbox3 = GUICtrlCreateCheckbox($C, 72, 104, 105, 25)
$Label1 = GUICtrlCreateLabel("0 MB", 216, 160, 52, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$m = 0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Checkbox1
$che = GUICtrlRead($Checkbox1)
If $che = 1 Then
$m = $m + 150
Else
$m = $m - 150
EndIf
GUICtrlSetData($Label1,$m&"MB")
Case $Checkbox2
$che = GUICtrlRead($Checkbox2)
If $che = 1 Then
$m = $m + 300
Else
$m = $m - 300
EndIf
GUICtrlSetData($Label1,$m&"MB")
Case $Checkbox3
$che = GUICtrlRead($Checkbox3)
If $che = 1 Then
$m = $m + 500
Else
$m = $m - 500
EndIf
GUICtrlSetData($Label1,$m&"MB")
EndSwitch
WEnd 回复 1# coocare01
看看是否达到你的要求。楼下的是否有更好的办法?#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 316, 216, 192, 114)
Local $a1,$b,$C
$a = "150"
$b = "300"
$C = "500"
Dim $X = 1, $Y = 1 , $Z = 1
$Checkbox1 = GUICtrlCreateCheckbox($a&"mb", 72, 24, 105, 25)
$Checkbox2 = GUICtrlCreateCheckbox($b&"mb", 72, 64, 105, 25)
$Checkbox3 = GUICtrlCreateCheckbox($C&"mb", 72, 104, 105, 25)
$Label1 = GUICtrlCreateLabel("0MB", 216, 160, 52, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
AdlibRegister("_abc", "1000")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _abc()
If GUICtrlRead($Checkbox1) = 1 And $X = 1 Then
GUICtrlSetData($Label1,$a + StringTrimRight (GUICtrlRead($Label1),2) & "MB")
$X += 1
ElseIf GUICtrlRead($Checkbox1) = 4 And $X = 2 Then
GUICtrlSetData($Label1,StringTrimRight (GUICtrlRead($Label1),2) - $a & "MB")
$X -= 1
EndIf
If GUICtrlRead($Checkbox2) = 1 And $Y = 1 Then
GUICtrlSetData($Label1,$B + StringTrimRight (GUICtrlRead($Label1),2) & "MB")
$Y += 1
ElseIf GUICtrlRead($Checkbox2) = 4 And $Y = 2 Then
GUICtrlSetData($Label1,StringTrimRight (GUICtrlRead($Label1),2) - $B & "MB")
$Y -= 1
EndIf
If GUICtrlRead($Checkbox3) = 1 And $Z = 1 Then
GUICtrlSetData($Label1,$C + StringTrimRight (GUICtrlRead($Label1),2) & "MB")
$Z += 1
ElseIf GUICtrlRead($Checkbox3) = 4 And $Z = 2 Then
GUICtrlSetData($Label1,StringTrimRight (GUICtrlRead($Label1),2) - $C & "MB")
$Z -= 1
EndIf
EndFunc
还是没抢到沙发。 2楼的方法不错,学习了。 2楼的简单明了.一般都用2楼的. 本帖最后由 tryhi 于 2010-12-7 20:01 编辑
谁先加我3点贡献,我加他50个金钱
------------------------------
nbmpe 已经加我了,我升高级了{:face (356):} 本帖最后由 水木子 于 2010-12-7 20:40 编辑
代码仅仅能满足眼前的需求是远远不够的,要尽可能的考虑远一些。
如:有成千上万个复选框,那该怎么办?难道要写上万行的代码吗?
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Local $avArray = ['150', '300', '500']
Local $nNumber
GUICreate("Form1", 300, 200)
$Checkbox1 = GUICtrlCreateCheckbox($avArray & 'MB', 80, 30, 100, 17)
$Checkbox2 = GUICtrlCreateCheckbox($avArray & 'MB', 80, 80, 100, 17)
$Checkbox3 = GUICtrlCreateCheckbox($avArray & 'MB', 80, 130, 100, 17)
$Label1 = GUICtrlCreateLabel('0 MB', 200, 160, 100, 33)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
Case $Checkbox1 To $Checkbox3
For $i = $Checkbox1 To $Checkbox3
If BitAND(GUICtrlRead($i), $GUI_CHECKED) Then $nNumber += $avArray[$i - 3]
Next
GUICtrlSetData($Label1, $nNumber & ' MB')
$nNumber = 0
EndSwitch
WEnd 本帖最后由 afan 于 2010-12-7 20:41 编辑
晕,木子先改了…… {:face (394):}GUICreate('Form1', 316, 216)
Local $v1 = 150, $v2 = 300, $v3 = 500, $Vz = 0
Local $Checkbox1 = GUICtrlCreateCheckbox($v1 & ' MB', 72, 24, 105, 25)
Local $Checkbox2 = GUICtrlCreateCheckbox($v2 & ' MB', 72, 64, 105, 25)
Local $Checkbox3 = GUICtrlCreateCheckbox($v3 & ' MB', 72, 104, 105, 25)
Local $Label1 = GUICtrlCreateLabel('0 MB', 216, 160, 52, 15, 0x0002)
Local $Val[$Checkbox3 + 1]
$Val[$Checkbox1] = $v1
$Val[$Checkbox2] = $v2
$Val[$Checkbox3] = $v3
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Checkbox1 To $Checkbox3
If GUICtrlRead($nMsg) = 1 Then
$Vz += $Val[$nMsg]
Else
$Vz -= $Val[$nMsg]
EndIf
GUICtrlSetData($Label1, $Vz & ' MB')
EndSwitch
WEnd #include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
dim $n,$Checkbox
$c=0
$n = 150
$n = 300
$n = 500
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 316, 216, 192, 114)
$Checkbox = GUICtrlCreateCheckbox("150 MB", 72, 24, 105, 25)
$Checkbox = GUICtrlCreateCheckbox("300 MB", 72, 64, 105, 25)
$Checkbox= GUICtrlCreateCheckbox("500 MB", 72, 104, 105, 25)
$Label1 = GUICtrlCreateLabel("0 MB", 216, 160, 52, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Checkbox
_ck()
Case $Checkbox
_ck()
Case $Checkbox
_ck()
EndSwitch
WEnd
Func _ck()
for $i=1 to 3Step 1
if GUICtrlRead($Checkbox[$i]) = 1 Then $c=$c+$n[$i]
Next
GUICtrlSetData($Label1,$c&" MB")
$c=0
EndFunc此贴为我第一次正规化写代码回贴。[color=SeaGreen]记名留恋
靠,这多人帮他解决问题,没人解决我的困境!{:face (239):} 晕,木子先改了……
afan 发表于 2010-12-7 20:38
Case $Checkbox1 To $Checkbox3
晕,竟然能这样写。我还搞的拆开的。日梦中... 回复 11# 绿色风
是啊!就是一道简单是加减题,也能探讨出很多技巧性的东西。 $hGUI = GUICreate("", 400, 300)
$iLabel = GUICtrlCreateLabel("0 MB", 100, 200, 100, 20)
$iCheckBox = GUICtrlCreateCheckBox("150", 40, 40, 90, 20)
GUICtrlCreateCheckBox("300", 40, 80, 90, 20)
GUICtrlCreateCheckBox("500", 40, 120, 90, 20)
$iSize = 0
GUISetState()
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case -3
ExitLoop
Case $iCheckBox To $iCheckBox + 2
If BitAND(GUICtrlRead($iMsg), 1) Then
$iSize += ($iMsg - $iCheckBox + 2) * 25 * ($iMsg - $iCheckBox + 3)
Else
$iSize -= ($iMsg - $iCheckBox + 2) * 25 * ($iMsg - $iCheckBox + 3)
EndIf
GUICtrlSetData($iLabel, $iSize & " MB")
EndSwitch
WEnd
pusofalse 发表于 2010-12-7 20:46 http://www.autoitx.com/images/common/back.gif
就怕LZ在创建Checkbox之前创建点别的 {:face (355):} 回复 14# afan
你意思是说$Checkbox = 后面不是这个复选框,那用你们的就备备了,我的嘛,已手动确定好的。{:face (377):}
页:
[1]
2