找回密码
 加入
搜索
查看: 6369|回复: 15

[AU3基础] 如何限制 输入框的 类型?[已解决]

 火.. [复制链接]
发表于 2012-5-8 09:12:02 | 显示全部楼层 |阅读模式
本帖最后由 魔导 于 2012-5-8 10:46 编辑

正解在3楼  半竹心  
小第想要限制  这两个  输入框为(整数,正数,输入框 的值在 0 至 23之间 ,输入框1 的值在 0 至 59 之间)
实在找不到代码 如何限制;  只好先用  IF   来判断啦
请前辈们指教指教,万分感谢!
$Form1 = GUICreate("练习",200,150,-1,-1)
GUICtrlCreateLabel("小时数:",5,2)
GUICtrlCreateLabel("分钟数:",5,22)
$input = GUICtrlCreateInput("",65,2,80,15)
$input1 = GUICtrlCreateInput("",65,22,80,15)
$button = GUICtrlCreateButton("确定",60,40,30,20)
GUISetState()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                                Case $button
                                        $Rinput = GUICtrlRead($input)
                                        $Rinput1 = GUICtrlRead($input1)
                                        If 0 = StringIsInt($Rinput) Or 0 = StringIsInt($Rinput1) Or $Rinput > 23 Or $Rinput < 0 Or $Rinput1 > 59 Or $Rinput1 < 0 Or StringLen($Rinput) > 2 Or StringLen($Rinput1) > 2 Then  
                                        MsgBox(0,'提示','请输入正确的小时值和分钟值'&@crlf&'《小时值:0 至 23  整数,分钟值:0 至 59  整数》')
                                        Else 
                                        MsgBox(0,'你输入的时间','Enter the Number of hours : '&$Rinput _
                                        &@CRLF&'Enter the Number of minutes : '&$Rinput1 _
                                        &@CRLF&'Time : '&$Rinput&':'&$Rinput1)
                                        Endif          
                EndSwitch
        wend
发表于 2012-5-8 10:07:01 | 显示全部楼层
input  控件没什么改头了, 自己处理键盘输入进行过滤又太麻烦,我也不会

为什么不用 GUICtrlCreateDate 呢

帮顶
发表于 2012-5-8 10:11:23 | 显示全部楼层
回复 1# 魔导


    真的怀疑你是不是跟我一样来混分的

$input1 = GUICtrlCreateInput("",65,22,80,15,$ES_NUMBER)


http://autoitx.com/thread-32069-1-1.html
 楼主| 发表于 2012-5-8 10:18:28 | 显示全部楼层
回复 3# 半芯竹


        回前辈的话  代码已经够清晰了   喜欢这样的表达是因为小弟经验不足(想不出其它办法所至)
替换这个码后小弟又出现了这类的问题:

本帖子中包含更多资源

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

×
发表于 2012-5-8 10:34:42 | 显示全部楼层
回复 1# 魔导


    http://www.autoitx.com/forum.php ... 1963&highlight=
已经有类似方法啊,建议你14-23行调整为子函数
 楼主| 发表于 2012-5-8 10:41:22 | 显示全部楼层
回复  魔导


   
已经有类似方法啊,建议你14-23行调整为子函数
楼上风云 发表于 2012-5-8 10:34


前辈的   方法已经看到了  ,用  IF 限制  值的大小 ,小弟想:是否有类似这样的码来限制:
GUICtrlSetLimit(-1,2)
GUICtrlCreateInput("",65,22,80,15,0x2000)
发表于 2012-5-8 10:44:06 | 显示全部楼层
combox 很好用的说


$Form1 = GUICreate("练习", 200, 150, -1, -1)
GUICtrlCreateLabel("小时数:", 5, 2)
GUICtrlCreateLabel("分钟数:", 5, 22)
$input = GUICtrlCreateCombo("请选择", 65, 2, 80, 15)
$item1 = ""
For $i = 0 To 22
        $item1 &= $i & "|"
Next
$item1 &= $i
GUICtrlSetData(-1, $item1)
$input1 = GUICtrlCreateCombo("请选择", 65, 22, 80, 15)
$item2 = ""
For $i = 0 To 58
        $item2 &= $i & "|"
Next
$item2 &= $i
GUICtrlSetData(-1, $item2)
$button = GUICtrlCreateButton("确定", 60, 40, 30, 20)
GUISetState()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $button
                        $Rinput = GUICtrlRead($input)
                        $Rinput1 = GUICtrlRead($input1)
                        If 0 = StringIsInt($Rinput) Or 0 = StringIsInt($Rinput1) Or $Rinput > 23 Or $Rinput < 0 Or $Rinput1 > 59 Or $Rinput1 < 0 Or StringLen($Rinput) > 2 Or StringLen($Rinput1) > 2 Then
                                MsgBox(0, '提示', '请输入正确的小时值和分钟值' & @CRLF & '《小时值:0 至 23  整数,分钟值:0 至 59  整数》')
                        Else
                                MsgBox(0, '你输入的时间', 'Enter the Number of hours : ' & $Rinput _
                                                 & @CRLF & 'Enter the Number of minutes : ' & $Rinput1 _
                                                 & @CRLF & 'Time : ' & $Rinput & ':' & $Rinput1)
                        EndIf
        EndSwitch
WEnd
 楼主| 发表于 2012-5-8 10:44:16 | 显示全部楼层
回复 3# 半芯竹


谢谢前辈耐心指教。。。。   
混分嘛,不是的(这一点现在很肯定,因为小的币已经用不完了(虽然很少))
发表于 2012-5-8 11:02:50 | 显示全部楼层
If _DateIsValid("1900-01-01 " & $Rinput & ":" & $Rinput1) Then
        MsgBox(0, '你输入的时间', 'Enter the Number of hours : ' & $Rinput _
         & @CRLF & 'Enter the Number of minutes : ' & $Rinput1 _
         & @CRLF & 'Time : ' & $Rinput & ':' & $Rinput1) 
Else
        MsgBox(0, '提示'&'2012/01/01 ' & $Rinput & ':' & $Rinput1, '请输入正确的小时值和分钟值' & @CRLF & '《小时值:0 至 23 整数,分钟值:0 至 59  整数》')
EndIf
发表于 2012-5-8 11:18:42 | 显示全部楼层
再给你一个简化的示例(请注意 _iif函数的使用)
$Form1 = GUICreate("练习",200,150,-1,-1)
GUICtrlCreateLabel("小时数:",5,2)

$input = GUICtrlCreateInput("",65,2,80,15)


$button = GUICtrlCreateButton("确定",60,40,30,20)
GUISetState()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $button
                      If Not check()   Then MsgBox(0,'','请注意输入范围')     
        EndSwitch
wend

Func check()
        $Rinput = GUICtrlRead($input)
        Return _iif($Rinput<23 And $Rinput>0,True,False)
EndFunc
   
func _iif ( $ftest , $vtrueval , $vfalseval ) ;
     if $ftest then
          return $vtrueval
     else
          return $vfalseval
     endif
endfunc
 楼主| 发表于 2012-5-8 11:23:42 | 显示全部楼层
回复 7# veket_linux


    感谢前辈指教
 楼主| 发表于 2012-5-8 11:27:54 | 显示全部楼层
回复 9# shqf


    万分感谢。。。
 楼主| 发表于 2012-5-8 11:29:06 | 显示全部楼层
本帖最后由 魔导 于 2012-5-8 11:35 编辑

回复 10# 楼上风云


    万分感谢,前辈果然是前辈.又有新东西要学咯
发表于 2012-5-8 11:38:25 | 显示全部楼层
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include "SendMessage.au3"

$Form1 = GUICreate("练习", 200, 150, -1, -1)
GUICtrlCreateLabel("小时数:", 5, 2)
GUICtrlCreateLabel("分钟数:", 5, 22)
$input = GUICtrlCreateInput("", 65, 2, 80, 15, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
GUICtrlSetLimit(-1, 2)
$input1 = GUICtrlCreateInput("", 65, 22, 80, 15, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
GUICtrlSetLimit(-1, 2)
$button = GUICtrlCreateButton("确定", 60, 40, 30, 20)
GUISetState()
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $button
                        $Rinput = GUICtrlRead($input)
                        $Rinput1 = GUICtrlRead($input1)
                        MsgBox(0, '你输入的时间', 'Enter the Number of hours : ' & $Rinput _
                                         & @CRLF & 'Enter the Number of minutes : ' & $Rinput1 _
                                         & @CRLF & 'Time : ' & $Rinput & ':' & $Rinput1)
        EndSwitch
WEnd

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
        Local $iCode = BitShift($wParam, 16)
                        Switch $iCode
                                Case $EN_CHANGE
                                        $TEXT=SENDMESS_GETTEXT($lParam)
                                        Switch $lParam
                                                Case GUICtrlGetHandle($input)
                                                        ToolTip("")
                                                        If $TEXT>23 Then 
                                                                ToolTip("超限,自动置最大值23")
                                                                SENDMESS_SETTEXT($lParam,23)
                                                        EndIf
                                                Case GUICtrlGetHandle($input1)
                                                        If $TEXT>59 Then SENDMESS_SETTEXT($lParam,59)
                                        EndSwitch
                        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc 


Func SENDMESS_GETTEXT($hWnd)
        Local $Len = _SendMessage($hWnd, 0x000E) + 1
        Local $Buffer = DllStructCreate("wchar Text[" & $Len & "]")
        _SendMessage($hWnd, 0x000D, $Len, $Buffer, 0, "wparam", "struct*")
        Return DllStructGetData($Buffer, "Text")
EndFunc  

Func SENDMESS_SETTEXT($hWnd,$sText)
        _SendMessage($hWnd, 0x000C, 0, $sText, 0, "wparam", "wstr")
EndFunc

评分

参与人数 1金钱 +10 收起 理由
楼上风云 + 10 厉害,学习了。

查看全部评分

发表于 2012-5-8 12:21:55 | 显示全部楼层
回复 14# 3mile
拓展成了一种新的样式了。厉害。
39行的数字23、44行中的数字59,如果提前定义的话,也可以用变量替代。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-30 11:28 , Processed in 0.092423 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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