以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  高手请看,代码能不能优化?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=11618)

--  作者:yanzhen2010
--  发布时间:2011/8/4 23:52:00
--  高手请看,代码能不能优化?

高手请看,代码能不能优化?

If e.DataCol.Name = "拼音码" Then
    If e.DataRow("拼音码")IsNot Nothing Then
        e.DataRow("拼音码") =e.DataRow("拼音码").split(":")(0)
    End If
End If
If e.DataCol.Name = "拼音码" Then
    Dim lb As DataRow
    lb = DataTables("收费项目").Find("[拼音码] = \'" & e.NewValue.split(":")(0) & "\'")
    If lb IsNot Nothing Then
        e.DataRow("项目类别") = lb("项目类别")
        e.DataRow("项目名称") = lb("项目名称")
    Else
        MsgBox("项目不存在,请重新输入!",64,"提示")
        e.DataRow("项目类别") = Nothing
        e.DataRow("项目名称") = Nothing
    End If
End If


--  作者:e-png
--  发布时间:2011/8/4 23:57:00
--  

恭喜了,不需要再优化了。


--  作者:狐狸爸爸
--  发布时间:2011/8/5 7:47:00
--  

可以省略一个if:

 

If e.DataCol.Name = "拼音码" Then
    If e.DataRow("拼音码")IsNot Nothing Then
        e.DataRow("拼音码") =e.DataRow("拼音码").split(":")(0)
    End If
    Dim lb As DataRow
    lb = DataTables("收费项目").Find("[拼音码] = \'" & e.NewValue.split(":")(0) & "\'")
    If lb IsNot Nothing Then
        e.DataRow("项目类别") = lb("项目类别")
        e.DataRow("项目名称") = lb("项目名称")
    Else
        MsgBox("项目不存在,请重新输入!",64,"提示")
        e.DataRow("项目类别") = Nothing
        e.DataRow("项目名称") = Nothing
    End If
End If