找回密码
 加入
搜索
查看: 5863|回复: 5

[GUI管理] Error:Variable used without being declared 【已解决】

  [复制链接]
发表于 2011-11-16 11:01:45 | 显示全部楼层 |阅读模式
本帖最后由 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
我水平不行,请高手指点,谢谢。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-11-16 11:11:14 | 显示全部楼层
鉴定完毕,没问题哈。。
发表于 2011-11-16 11:37:23 | 显示全部楼层
难道是exit的问题?
发表于 2011-11-16 12:46:02 | 显示全部楼层
我这里测试也没有问题
 楼主| 发表于 2011-11-16 14:41:35 | 显示全部楼层
解决了,是安装的autoit版本问题,我安装的是3.2.4.9,卸载后安装上3.3.6.1,将此AU3转成exe,不再出现出错的提示框了。
发表于 2011-11-16 18:04:18 | 显示全部楼层
回复 5# prof


    哥们版本太低了,,哈哈哈
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-20 23:26 , Processed in 0.118413 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表