帮我看看这段代码的问题?
本帖最后由 xg911335 于 2009-7-22 10:30 编辑#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 223, 133, 338, 267)
$Input1 = GUICtrlCreateInput("", 72, 20, 121, 21)
$Button1 = GUICtrlCreateButton("test", 78, 98, 68, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
If @error = 1 Then
Exit
EndIf
$strlen = StringLen($input1)
MsgBox(0,"",$strlen);测试, -----------------------------------这里怎么返回1啊?
If $strlen = "" Then
MsgBox(16,"1","你没有输入任何数字,请重新输入")
ElseIf StringIsDigit($input1) <> 1 Then ;-----------------------------------这个地方也有问题。
MsgBox(16,"2","您输入的包涵其它字符")
ElseIf $strlen <> 13 Then ;-------------------------------------------------不管是值是空还是什么都在判断在这里来了?
MsgBox(16,"3","您输入的数字可能小于13位或大于13位")
Else
Exit
EndIf
EndSwitch
WEnd我晕。我另外一个判断时间的小程序和上面一样,那个就没有问题,可这个怎么会出问题。 本帖最后由 afan 于 2009-7-21 15:43 编辑
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 223, 133, 338, 267)
$Input1 = GUICtrlCreateInput("", 72, 20, 121, 21)
$Button1 = GUICtrlCreateButton("test", 78, 98, 68, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$strlen = StringLen(GUICtrlRead($Input1))
If $strlen = "" Then
MsgBox(16, "1", "你没有输入任何数字,请重新输入")
ElseIf StringIsDigit(GUICtrlRead($Input1)) <> 1 Then
MsgBox(16, "2", "您输入了含有数字以外的字符")
ElseIf $strlen <> 13 Then
MsgBox(16, "3", "您输入的数字为" & $strlen & "位,需要13位")
ElseIf $strlen = 13 Then
MsgBox(64, "ok", "搞定了,这才是正宗S13 ")
EndIf
EndSwitch
WEnd
本帖最后由 afan 于 2009-7-21 18:50 编辑
其实在 GUICtrlCreateInput 处修改一下,可以减少一些繁琐判断
而且,Case $Button1 里面的循环也是多余的
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 223, 133, 338, 267)
$Input1 = GUICtrlCreateInput("", 72, 20, 121, 21, $ES_NUMBER)
GUICtrlSetLimit(-1, 13)
$Button1 = GUICtrlCreateButton("test", 78, 98, 68, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$strlen = StringLen(GUICtrlRead($Input1))
If $strlen = 13 Then
MsgBox(64, "ok", "搞定了,这才是正宗S13 ")
Else
MsgBox(16, "no", "您输入的数字为" & $strlen & "位,需要13位")
EndIf
EndSwitch
WEnd
学习一下。。
页:
[1]