以文本方式查看主题

-  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=24849)

--  作者:Fotable
--  发布时间:2012/10/24 19:39:00
--  狐爸,优化帮助文件中的一段代码。

在帮助文件中关于beforeaddfile事件

http://www.foxtable.com/help/topics/2638.htm

 

If e.DataCol.name = "文件" Then
    If e.DataRow.IsNull(
"用户") = False
        Dim pth As String = "c:\\data\\" & e.DataRow(
"用户")
        If FileSys.DirectoryExists(pth) Then
            e.Path = pth
        Else
            e.path  = "c:\\data"
        End If
    Else
        e.path = "c:\\data"
   
End If
End
If

 

这段代码有点繁琐,可以优化代码为:

If e.DataCol.name = "文件" Then

    e.path  = "c:\\data"

    If not e.DataRow.IsNull("用户") andalso FileSys.DirectoryExists(e.path & e.DataRow("用户")) then
        
    e.Path = e.path & e.DataRow("用户")
    End If

End If

[此贴子已经被作者于2012-10-24 19:41:37编辑过]

--  作者:狐狸爸爸
--  发布时间:2012/10/24 21:13:00
--  
嗯,你写得不错。