| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 349 人关注过本帖
标题:如何简化优化代码
取消只看楼主 加入收藏
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:334
专家分:134
注 册:2009-3-16
结帖率:85.71%
收藏
已结贴  问题点数:20 回复次数:2 
如何简化优化代码
程序代码:
    If Me.Combo1(0) <> "" And Me.Combo1(1) <> "" And Me.Combo1(2) <> "" And Me.Combo1(3) <> "" Then
        SQL = "select * from DataList"
        SQL = SQL + " where [UploadSN] ='" & Me.Combo1(0) & "' and [BuyerName] ='" & Me.Combo1(1) & "' and [MaterialPart] ='" & Me.Combo1(2) & "' and [YesOrNo] ='" & Me.Combo1(3) & "'"

    ElseIf Me.Combo1(0) <> "" And Me.Combo1(1) = "" And Me.Combo1(2) = "" And Me.Combo1(3) = "" Then
        SQL = "select * from DataList where [UploadSN] ='" & Me.Combo1(0) & "' "

    ElseIf Me.Combo1(0) <> "" And Me.Combo1(1) <> "" And Me.Combo1(2) = "" And Me.Combo1(3) = "" Then
        SQL = "select * from DataList where [UploadSN] ='" & Me.Combo1(0) & "' and [BuyerName] ='" & Me.Combo1(1) & "' "

    ElseIf Me.Combo1(0) <> "" And Me.Combo1(1) <> "" And Me.Combo1(2) <> "" And Me.Combo1(3) = "" Then
        SQL = "select * from DataList where [UploadSN] ='" & Me.Combo1(0) & "' and [BuyerName] ='" & Me.Combo1(1) & "' and [MaterialPart] ='" & Me.Combo1(2) & "' "

    ElseIf Me.Combo1(0) = "" And Me.Combo1(1) = "" And Me.Combo1(2) = "" And Me.Combo1(3) <> "" Then
        SQL = "select * from DataList where [YesOrNo] ='" & Me.Combo1(3) & "'"

    ElseIf Me.Combo1(0) = "" And Me.Combo1(1) = "" And Me.Combo1(2) <> "" And Me.Combo1(3) <> "" Then
        SQL = "select * from DataList where [MaterialPart] ='" & Me.Combo1(2) & "' and [YesOrNo] ='" & Me.Combo1(3) & "'"

    ElseIf Me.Combo1(0) = "" And Me.Combo1(1) <> "" And Me.Combo1(2) <> "" And Me.Combo1(3) <> "" Then
        SQL = "select * from DataList where [BuyerName] ='" & Me.Combo1(1) & "' and [MaterialPart] ='" & Me.Combo1(2) & "' and [YesOrNo] ='" & Me.Combo1(3) & "'"

    ElseIf Me.Combo1(0) <> "" And Me.Combo1(1) = "" And Me.Combo1(2) <> "" And Me.Combo1(3) = "" Then
        SQL = "select * from DataList"
        SQL = SQL + " where [UploadSN] ='" & Me.Combo1(0) & "' and [MaterialPart] ='" & Me.Combo1(2) & "'"
    ElseIf Me.Combo1(0) = "" And Me.Combo1(1) = "" And Me.Combo1(2) <> "" And Me.Combo1(3) = "" Then
        SQL = "select * from DataList"
        SQL = SQL + " where [MaterialPart] ='" & Me.Combo1(2) & "'"

    ElseIf Me.Combo1(0) <> "" And Me.Combo1(1) = "" And Me.Combo1(2) = "" And Me.Combo1(3) <> "" Then
        SQL = "select * from DataList"
        If Me.Combo1(3).Text = "Null" Then
            SQL = SQL + " where [UploadSN] ='" & Me.Combo1(0) & "' and [YesOrNo] is null"
        Else
            SQL = SQL + " where [UploadSN] ='" & Me.Combo1(0) & "' and [YesOrNo] ='" & Me.Combo1(3) & "'"
        End If

    ElseIf Me.Combo1(0) = "" And Me.Combo1(1) = "" And Me.Combo1(2) = "" And Me.Combo1(3) = "" Then
        MsgBox "Pls selct one condition", vbCritical, "Caution"
        Exit Sub
    End If
搜索更多相关主题的帖子: 如何 
2014-03-25 17:04
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:334
专家分:134
注 册:2009-3-16
收藏
得分:0 
回复 2楼 lowxiong
谢谢版主
2014-03-25 18:44
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:334
专家分:134
注 册:2009-3-16
收藏
得分:0 
回复 4楼 风吹过b
谢谢斑竹,太厉害了,学习ing...
2014-03-26 15:07
快速回复:如何简化优化代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023053 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved