#42006/6/24 13:05:42
我是在模拟一个软件,它是这样实现的,我是没有办法呀!
我做的是这样的:
on keyDown
-- alert the key
case the keyCode of:
-- case the key of
82,83,84,85,86,87,88,89,91,92:
--小键盘数字0-9
checkInput("inputBox",the key,-85,85,2)
18,19,20,21,23,22,26,28,25,29:
--大键盘数字9-0
checkInput("inputBox",the key,-85,85,2)
27,24,47:
--大键盘上的负号,正号,小数点
checkInput("inputBox",the key,-85,85,2)
70,78,65:
--小键盘上的负号,正号,小数点
checkInput("inputBox",the key,-85,85,2)
51:
--退格键
bkSpace("inputBox")
36:
--回车,用于执行确认输入程序
alert("回车啦!")
end case
end
--判断成员memName的文本连接inputChar后转化得到的数字,
--是否大于等于lBound并小于等于rBound,同时要保证小数位数不大于decimal
on checkInput memName,inputChar,lBound,rBound,decimal
--确定成员memName的文本长度
memTextLength = member(memName).text.length
--确定小数点的位置,如不为0,则证明该数字中已经有小数点
decimalPositon = offset(".", member(memName).text)
--处理正号、负号:正号、负号只能出现在数字的第一个字符处——即memTextLength=0
if inputChar = "=" then
inputChar = "+"
end if
if (inputChar = "-" or inputChar = "+") and memTextLength<>0 then
beep
exit
end if
--处理小数点:小数点前至少有一位数字,且只能有一个小数点;如果decimal=0,则不允许接受小数点
if inputChar = "." and (decimal=0 or decimalPositon<>0 or memTextLength=0 or (memTextLength<>0 and "0123456789" contains the last char of member(memName).text=false)) then
beep
exit
end if
--处理数字“0”
if inputChar = "0" and memTextLength=0 then
beep
exit
end if
--处理小数位数
if decimalPositon <> 0 and decimalPositon = memTextLength-2 then
beep
exit
end if
if member("inputBox").text&the key.length = 1 and "-+" contains the key then
put the key after member("inputBox")
exit
end if
--判断连接inputChar后得到的数字是否超过界限
if float(member("inputBox").text&the key)>rBound or float(member("inputBox").text&the key)<lBound then
beep
exit
end if
put inputChar after member("inputBox")
end
--删除成员memName的最后一个字符,如果为“空”则Beep
on bkSpace memName
if member(memName).text.length<>0 then
member(memName).text = chars(member(memName).text,1,member(memName).text.length-1)
else
beep
end if
end
请各位仁兄帮忙指正。看看有比这个更简单合理的做法吗?
闭起眼睛看人生