|
本帖最后由 prof 于 2011-11-16 17:36 编辑
在网上(http://bbs.wglm.net/thread-118269-1-1.html)看到计算BMI(体重指数)的代码,以AU3保存,略加更改,可以正常运行,转成exe后运行报错。Line 0 (File "C:\Document and Settings\administrator\My Documents\BMI.exe"):
Case $GUI_EVENT_CLOSE
Case ^ ERROR
Error: Variable used without being declared
代码如下:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Dim $bmi
$bmi=1
$Form1 = GUICreate("BMI指数计算器", 226, 285)
$Input1 = GUICtrlCreateInput("0", 85, 32, 91, 21)
$lab1 = GUICtrlCreateLabel("身高(M)", 5, 32, 78, 17)
$Input2 = GUICtrlCreateInput("0", 85, 64, 91, 21)
$Label1 = GUICtrlCreateLabel("体重(KG)", 5, 64,78, 17)
$Label2 = GUICtrlCreateLabel("BMI", 8, 96, 50, 17)
$Label3 = GUICtrlCreateLabel("", 64, 96, 120, 17)
$Button1 = GUICtrlCreateButton("计算", 72, 120, 75, 25)
$Label4 = GUICtrlCreateLabel("说明:"& @CRLF &@CRLF&"国人BMI标准为:" & @CRLF & "BMI<18.5为偏瘦,18.5-23.9为正常,BMI≥24为超重,BMI≥28为肥胖。", 24, 160, 180,150)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$hight=GUICtrlRead($Input1)
$weight=GUICtrlRead($Input2)
If (StringIsDigit($hight) Or StringIsFloat($hight)) And (StringIsDigit($weight) Or StringIsFloat($weight)) Then
$bmi=Round($weight/($hight*$hight),1)
Select
Case $bmi<18.5
$fault=" 请增加营养"
Case $bmi>=18.5 And $bmi<24
$fault=" 标准身材"
Case $bmi>=24 And $bmi<28
$fault=" 太丰满了"
Case $bmi>=28
$fault=' 请少吃多动'
EndSelect
GUICtrlSetData($Label3,$bmi & $fault)
GUICtrlSetColor($Label3,0xff0000)
Else
MsgBox(0,'','请正确输入',5)
ContinueLoop
EndIf
EndSwitch
WEnd
我水平不行,请高手指点,谢谢。 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入
×
|