select多重判断问题[已解决]
本帖最后由 xyhqqaa 于 2017-9-15 09:56 编辑#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 278, 438, 192, 124)
$Input1 = GUICtrlCreateInput("", 120, 56, 121, 21)
$Input2 = GUICtrlCreateInput("", 120, 96, 121, 21)
$Input3 = GUICtrlCreateInput("", 120, 136, 121, 21)
$Input4 = GUICtrlCreateInput("", 120, 176, 121, 21)
$Input5 = GUICtrlCreateInput("", 120, 216, 121, 21)
$Input6 = GUICtrlCreateInput("", 112, 256, 121, 21)
$Button1 = GUICtrlCreateButton("查询", 64, 304, 155, 49)
$Label1 = GUICtrlCreateLabel("条件1", 56, 56, 36, 17)
$Label2 = GUICtrlCreateLabel("条件2", 56, 96, 36, 17)
$Label3 = GUICtrlCreateLabel("条件3", 56, 136, 36, 17)
$Label4 = GUICtrlCreateLabel("条件4", 56, 184, 36, 17)
$Label5 = GUICtrlCreateLabel("条件5", 56, 216, 36, 17)
$Label6 = GUICtrlCreateLabel("条件6", 56, 256, 36, 17)
$Group1 = GUICtrlCreateGroup("多重判断", 32, 40, 233, 169)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
panduan()
EndSwitch
WEnd
Func panduan()
$a=GUICtrlRead($Input1)
$b=GUICtrlRead($Input2)
$c=GUICtrlRead($Input3)
$d=GUICtrlRead($Input4)
$e=GUICtrlRead($Input5)
$f=GUICtrlRead($Input6)
Select
Case $a<>"" And $B<>""
MsgBox("","","第一二条件不为空")
Case$a<>"" And $c<>""
MsgBox("","","第一三条件不为空")
Case$a<>"" And $d<>""
MsgBox("","","第一四不为空")
Case$b<>"" And $c<>""
MsgBox("","","第二三不为空")
Case $b<>"" And $d<>""
MsgBox("","","第二四不为空")
Case $C<>"" And $d<>""
MsgBox("","","第三四不为空")
EndSelect
Select
Case $a<>""
MsgBox("","","第一不为空")
Case$b<>""
MsgBox("","","第二不为空")
Case$C<>""
MsgBox("","","第三不为空")
Case$D<>""
MsgBox("","","第四不为空")
Case $a<>""
MsgBox("","","第五不为空")
Case$F<>""
MsgBox("","","第六不为空")
EndSelect
EndFunc以上是代码,新手求助请教大哥们,目的是当输入一个条件的时候,运行单条件判断。输入两个条件的时候,运行多条件判断。但是现在这代码运行结果是单条件判断跟多条件判断同时运行。。。萌新求指教,或者有更好的方法,求大神给个思路,小弟比较傻。。。
我的逻辑有问题。。下面大哥的方法学习了。我应该好好思考自己的问题~~~
是不是要这样的#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 278, 438, 192, 124)
$Input1 = GUICtrlCreateInput("", 120, 56, 121, 21)
$Input2 = GUICtrlCreateInput("", 120, 96, 121, 21)
$Input3 = GUICtrlCreateInput("", 120, 136, 121, 21)
$Input4 = GUICtrlCreateInput("", 120, 176, 121, 21)
$Input5 = GUICtrlCreateInput("", 120, 216, 121, 21)
$Input6 = GUICtrlCreateInput("", 112, 256, 121, 21)
$Button1 = GUICtrlCreateButton("查询", 64, 304, 155, 49)
$Label1 = GUICtrlCreateLabel("条件1", 56, 56, 36, 17)
$Label2 = GUICtrlCreateLabel("条件2", 56, 96, 36, 17)
$Label3 = GUICtrlCreateLabel("条件3", 56, 136, 36, 17)
$Label4 = GUICtrlCreateLabel("条件4", 56, 184, 36, 17)
$Label5 = GUICtrlCreateLabel("条件5", 56, 216, 36, 17)
$Label6 = GUICtrlCreateLabel("条件6", 56, 256, 36, 17)
$Group1 = GUICtrlCreateGroup("多重判断", 32, 40, 233, 169)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
panduan()
EndSwitch
WEnd
Func panduan()
Local $str = ''
For $i = 1 To 6
If GUICtrlRead(Eval('Input' & $i)) <> '' Then $str &= $i & '、'
Next
If $str <> '' Then
$str = StringTrimRight($str,1)
If StringInStr($str, '、') Then
Return MsgBox(512, '多个', '第 ' & $str & ' 不为空!',0,$Form1)
Else
Return MsgBox(512, '单个', '第 ' & $str & ' 不为空!',0,$Form1)
EndIf
EndIf
EndFunc ;==>panduan 回复 2# zghwelcome
哇哇。。。谢谢。。。太牛了。。谢谢。。我好好学习消化下,比我简单好太多。。感谢您。。谢谢 回复 3# xyhqqaa
如果解決了 請修改標題 回复 4# kk_lee69
kk_lee69大哥,不好意思,正在参考别人的例子。zghwelcome大哥的代码显示效果跟我希望显示效果要求差不多,但是由于我想实现对输入框状态判断的同时还要对输入框内的词进行类似数据库查询的操作,所以我担心没解决好,后面我重复提问不好,所以暂时没更改解决状态,不好意思。 楼主是逻辑思维问题,就好比,你要判断一个人是男是女,又要判断是儿童,少年,壮年,老人。而你设计了2个顺次的判断,自然要运行2次。不知道为什么你要判断那么多“不为空”,按照一般逻辑,多条件查询先判断哪些条件输入的是空。因为空可以意味着查询所有,而有的空意味着0,好好理一理你这个软件的流程。这样就好写代码了。
对于多条件SQL查询(不知道你是不是用于SQL查询),大部分输入值是不用判断的。除非数字和空格的处理。
一般的语句是如下的样子:
"SELECT * FROM 你要查询的表 where 1=1 and (条件1字段 like'%条件1输入值%' )and (条件2字段like 条件2输入值 ) and 。。。。。有多少条件输入多少。当然看你条件的类别把LIKE换成等于或者between等。
这样某个条件没有输入,就是此条件的全部查询了。
希望对你有帮助。 #include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 278, 438, 192, 124)
$Input1 = GUICtrlCreateInput("", 120, 56, 121, 21)
$Input2 = GUICtrlCreateInput("", 120, 96, 121, 21)
$Input3 = GUICtrlCreateInput("", 120, 136, 121, 21)
$Input4 = GUICtrlCreateInput("", 120, 176, 121, 21)
$Input5 = GUICtrlCreateInput("", 120, 216, 121, 21)
$Input6 = GUICtrlCreateInput("", 112, 256, 121, 21)
$Button1 = GUICtrlCreateButton("查询", 64, 304, 155, 49)
$Label1 = GUICtrlCreateLabel("条件1", 56, 56, 36, 17)
$Label2 = GUICtrlCreateLabel("条件2", 56, 96, 36, 17)
$Label3 = GUICtrlCreateLabel("条件3", 56, 136, 36, 17)
$Label4 = GUICtrlCreateLabel("条件4", 56, 184, 36, 17)
$Label5 = GUICtrlCreateLabel("条件5", 56, 216, 36, 17)
$Label6 = GUICtrlCreateLabel("条件6", 56, 256, 36, 17)
$Group1 = GUICtrlCreateGroup("多重判断", 32, 40, 233, 169)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
panduan()
EndSwitch
WEnd
Func panduan()
Local $read
$read=GUICtrlRead($Input1)
$read=GUICtrlRead($Input2)
$read=GUICtrlRead($Input3)
$read=GUICtrlRead($Input4)
$read=GUICtrlRead($Input5)
$read=GUICtrlRead($Input6)
Local $temp = ['一','二','三','四','五','六']
Local $out = ''
For $i = 0 To 5
If $read[$i] <> '' Then $out &= $temp[$i]
Next
MsgBox("","","第"&$out&"不为空")
EndFunc 回复 6# macran
您的回答是我想要的。。。谢谢您。。。我的SQL确实有待加强 厉害,那么长一窜代码,被精简到这么短,还是老鸟辣
页:
[1]