|
本帖最後由 rictirse 於 2013-2-10 13:56 編輯
第一種作法 按鈕式,這種做法是比較常見的做法,輸入完 身高體重後 按按鈕 才進行計算
[code=autoit]#include <GUIConstantsEx.au3>
Opt ( "GUIOnEventMode", 1)
Dim $BMI, $w, $h, $Comment
GUICreate ( "", 390, 115)
GUISetOnEvent ( $GUI_EVENT_CLOSE, "_Exit") ;;OnEvent Mod call func _Exit
GUISetFont ( 10, 800);; 宣告預設的字體 與 大小
GUICtrlCreateLabel ( "Height (cm)", 20, 20, 120) ;; 建立 Label
GUICtrlSetColor ( -1, 0x1260FF)
GUICtrlCreateLabel ( "Width (kg)", 110, 20)
GUICtrlSetColor ( -1, 0x1260FF)
GUICtrlCreateLabel ( "BMI", 315, 20)
GUICtrlSetColor ( -1, 0x1260FF)
$iw = GUICtrlCreateInput ( "", 20, 50, 80, 25);; 建立 Input
GUICtrlSetColor ( -1, 0xEE7600)
$ih = GUICtrlCreateInput ( "", 110, 50, 80, 25)
GUICtrlSetColor ( -1, 0xEE7600)
$btn = GUICtrlCreateButton ( "Sol" , 200, 50, 80 ,25)
GUICtrlSetOnEvent ( -1, "_Sol")
$sol = GUICtrlCreateInput ( "", 290, 50, 80, 25)
GUICtrlSetColor ( -1, 0xEE7600)
$review = GUICtrlCreateLabel ( "評語:", 25, 85, 250, 25)
GUICtrlSetColor ( -1, 0xEE7600)
GUISetState ()
While True
Sleep (10)
WEnd
Func _Exit()
Exit
EndFunc
Func _Sol()
If GUICtrlRead ($iw) <> "" And GUICtrlRead ($ih) <> "" Then;; input (iw)、(ih) 內容不等於 空白時執行
$w = GUICtrlRead ($iw) ;; 變數 w= input (iw) 內的 data
$h = GUICtrlRead ($ih) ;; 變數 h = input (ih) 內的 data
$w /= 100;; 單位換算 cm 轉 m
$BMI = $h/($w^2) ;; 公式 BMI = 身高(kg) / 體重平方(m)
If $BMI < 18.5 Then
$Comment = "體重過輕"
GUICtrlSetColor ( $review, 0x00CD00);; 體重過輕 綠色
ElseIf $BMI <= 24 Then
$Comment = "正常體重"
GUICtrlSetColor ( $review, 0x87CEFF);; 正常體重 天藍色
ElseIf $BMI <= 27 Then
$Comment = "過重"
GUICtrlSetColor ( $review, 0xEE9A00);; 過重 橙色
ElseIf $BMI <= 30 Then
$Comment = "輕度過胖"
GUICtrlSetColor ( $review, 0xEE4000);; 輕度過重 橘紅色
ElseIf $BMI <= 35 Then
$Comment = "中度過胖"
GUICtrlSetColor ( $review, 0xFF0000);; 中度過重 鮮紅色
Else
$Comment = "重度過胖"
GUICtrlSetColor ( $review, 0xBF3EFF);; 重度過重 紫色
EndIf
GUICtrlSetData ( $sol, StringFormat ( "%f", $BMI)) ;;修改 Input (sol)內的資料 使用 BMI 取代
GUICtrlSetData ( $review, StringFormat ( "評語:%s", $Comment)) ;;修改 Input (review)內的資料 填入評語 %f = 小數點下 六位數
EndIf
EndFunc[/code]
|
本帖子中包含更多資源
您需要 登入 才可以下載或查看,沒有帳號?註冊
x
|