Foxtable(狐表)用户栏目专家坐堂 → 高手请看,代码能不能优化?


  共有9661人关注过本帖树形打印复制链接

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

帅哥哟,离线,有人找我吗?
yanzhen2010
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:212 积分:1564 威望:0 精华:0 注册:2011/7/20 21:00:00
高手请看,代码能不能优化?  发帖心情 Post By: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
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1695 积分:10725 威望:0 精华:0 注册:2009/10/25 16:45:00
  发帖心情 Post By:2011/8/4 23:57:00 [只看该作者]

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


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251048 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By: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


 回到顶部