$gu_Form1 = GUICreate("EXCEL", 600, 100, -1, -1)
$BUT1 = GUICtrlCreateButton("計算+值and-值平均值 ", 2, 50, 126, 26, 0x01)
Local $EO = 6, $KU = 2, $KI = 56, $KO = 17
Local $SL[10]
For $i = 0 To 9
$SL[$i] = GUICtrlCreateLabel("", $EO, $KU, $KI, $KO, 0x01)
$EO += 57
GUICtrlSetBkColor($SL[$i], 0xFFFFFF)
GUICtrlSetData($SL[$i], -3 + $i)
GUICtrlSetFont($SL[$i], 12)
Next
$X = 0
$Y = 0
;=============================================================================
GUISetState(@SW_SHOW)
Local $nMsg
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $BUT1
$sum1 = 0
$n1 = 0
$avg1 = 0
$sum2 = 0
$n2 = 0
$avg2 = 0
$data = 0
For $i = 0 To 9
$data = Number(GUICtrlRead($SL[$i]))
If $data > 0 Then
$sum1 += $data
$n1 += 1
EndIf
If $data < 0 Then
$sum2 += $data
$n2 += 1
EndIf
Next
If $n1 Then
$avg1 = $sum1 / $n1
MsgBox(0, "正数平均值=", $avg1)
Else
MsgBox(0, "抱歉", "正数为0个")
EndIf
If $n2 Then
$avg2 = $sum2 / $n2
MsgBox(0, "负数平均值=", $avg2)
Else
MsgBox(0, "抱歉", "负数为0个")
EndIf
EndSwitch
WEnd
|