找回密码
 加入
搜索
查看: 2115|回复: 8

[效率算法] select多重判断问题[已解决]

  [复制链接]
发表于 2017-9-13 12:08:57 | 显示全部楼层 |阅读模式
本帖最后由 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
以上是代码,新手求助请教大哥们,目的是当输入一个条件的时候,运行单条件判断。输入两个条件的时候,运行多条件判断。但是现在这代码运行结果是单条件判断跟多条件判断同时运行。。。萌新求指教,或者有更好的方法,求大神给个思路,小弟比较傻。。。



我的逻辑有问题。。下面大哥的方法学习了。我应该好好思考自己的问题~~~

本帖子中包含更多资源

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

×
发表于 2017-9-13 12:25:46 | 显示全部楼层
是不是要这样的
#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

评分

参与人数 1金钱 +20 收起 理由
xyhqqaa + 20 感谢您

查看全部评分

 楼主| 发表于 2017-9-13 13:02:18 | 显示全部楼层
回复 2# zghwelcome


哇哇。。。谢谢。。。太牛了。。谢谢。。我好好学习消化下,比我简单好太多。。感谢您。。谢谢
发表于 2017-9-13 16:24:30 | 显示全部楼层
回复 3# xyhqqaa


    如果解決了 請修改標題
 楼主| 发表于 2017-9-13 16:32:17 | 显示全部楼层
回复 4# kk_lee69

kk_lee69大哥,不好意思,正在参考别人的例子。zghwelcome大哥的代码显示效果跟我希望显示效果要求差不多,但是由于我想实现对输入框状态判断的同时还要对输入框内的词进行类似数据库查询的操作,所以我担心没解决好,后面我重复提问不好,所以暂时没更改解决状态,不好意思。
发表于 2017-9-14 10:24:19 | 显示全部楼层
楼主是逻辑思维问题,就好比,你要判断一个人是男是女,又要判断是儿童,少年,壮年,老人。而你设计了2个顺次的判断,自然要运行2次。不知道为什么你要判断那么多“不为空”,按照一般逻辑,多条件查询先判断哪些条件输入的是空。因为空可以意味着查询所有,而有的空意味着0,好好理一理你这个软件的流程。这样就好写代码了。
对于多条件SQL查询(不知道你是不是用于SQL查询),大部分输入值是不用判断的。除非数字和空格的处理。
一般的语句是如下的样子:
"SELECT * FROM 你要查询的表 where 1=1 and (条件1字段 like'%条件1输入值%' )  and (条件2字段like 条件2输入值 ) and 。。。。。有多少条件输入多少。当然看你条件的类别把LIKE换成等于或者between等。
这样某个条件没有输入,就是此条件的全部查询了。
希望对你有帮助。

评分

参与人数 1金钱 +10 收起 理由
xyhqqaa + 10 谢谢您,你说的没错,我知道我的逻辑确实有 ...

查看全部评分

发表于 2017-9-14 14:04:49 | 显示全部楼层
#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[6]
        $read[0]=GUICtrlRead($Input1)
        $read[1]=GUICtrlRead($Input2)
        $read[2]=GUICtrlRead($Input3)
        $read[3]=GUICtrlRead($Input4)
        $read[4]=GUICtrlRead($Input5)
        $read[5]=GUICtrlRead($Input6)




        Local $temp[6] = ['一','二','三','四','五','六']
        Local $out = ''

        For $i = 0 To 5
                If $read[$i] <> '' Then $out &= $temp[$i]
        Next

        MsgBox("","","第"&$out&"不为空")




EndFunc

评分

参与人数 1金钱 +10 收起 理由
xyhqqaa + 10 哇,谢谢您。又看到一种新的方法。虽然不是 ...

查看全部评分

 楼主| 发表于 2017-9-15 09:57:11 | 显示全部楼层
回复 6# macran


    您的回答是我想要的。。。谢谢您。。。我的SQL确实有待加强
发表于 2017-9-18 08:56:00 | 显示全部楼层
厉害,那么长一窜代码,被精简到这么短,还是老鸟辣
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-20 17:33 , Processed in 0.087298 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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