Foxtable(狐表)用户栏目专家坐堂 → 大师请教输出


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

主题:大师请教输出

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


加好友 发短信
等级:狐神 帖子:5061 积分:13092 威望:0 精华:0 注册:2014/5/15 21:34:00
大师请教输出  发帖心情 Post By:2019/8/23 9:26:00 [只看该作者]

大师:下面的代码:

全局代码

 

<DllImport("kernel32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto, SetLastError:=True)> _
Public Function FindFirstFile(ByVal pFileName As String, ByRef pFindFileData As WIN32_FIND_DATA) As IntPtr
End Function
<DllImport("kernel32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto, SetLastError:=True)> _
Public Function FindNextFile(ByVal hndFindFile As IntPtr, ByRef lpFindFileData As WIN32_FIND_DATA) As Boolean
End Function
<DllImport("kernel32.dll", SetLastError:=True)> _
Public Function FindClose(ByVal hndFindFile As IntPtr) As Boolean
End Function

<Serializable, StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto), BestFitMapping(False)> _
Public Structure WIN32_FIND_DATA
Public dwFileAttributes As IO.FileAttributes
Public ftCreationTime_dwLowDateTime As UInteger
Public ftCreationTime_dwHighDateTime As UInteger
Public ftLastAccessTime_dwLowDateTime As UInteger
Public ftLastAccessTime_dwHighDateTime As UInteger
Public ftLastWriteTime_dwLowDateTime As UInteger
Public ftLastWriteTime_dwHighDateTime As UInteger
Public nFileSizeHigh As UInteger
Public nFileSizeLow As UInteger
Public dwReserved0 As Integer
Public dwReserved1 As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Public cFileName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=14)> _
Public cAlternateFileName As String
End Structure

Public Function EnumerateFiles(ByVal path As String, ByVal Optional searchPattern As String = "*.*", ByVal Optional searchOption As IO.SearchOption = IO.SearchOption.AllDirectories)
Dim hFind As IntPtr = -1
Dim FindFileData As WIN32_FIND_DATA = Nothing

hFind = FindFirstFile(IO.Path.Combine(path, searchPattern), FindFileData)
If hFind <> -1 Then
    
    Do
        If FindFileData.cFileName.Equals(".") OrElse FindFileData.cFileName.Equals("..") Then Continue Do
        
        If  searchOption = io.SearchOption.AllDirectories AndAlso ((FindFileData.dwFileAttributes And io.FileAttributes.Directory) = io.FileAttributes.Directory) Then
            'output.show(io.Path.Combine(path, FindFileData.cFileName))
            EnumerateFiles(io.Path.Combine(path, FindFileData.cFileName))
        Else
            output.show(io.Path.Combine(path, FindFileData.cFileName))
        End If

    Loop While FindNextFile(hFind, FindFileData)
    FindClose(hFind)
    
End If

End Function


请问如何把红色部分输出到窗口中的一个标签显示?





 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110738 积分:563610 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/8/23 9:49:00 [只看该作者]

函数添加一个参数,把窗口或者窗口名称传进来

Public Function EnumerateFiles(ByVal path As String, ByVal Optional searchPattern As String = "*.*", ByVal Optional searchOption As IO.SearchOption = IO.SearchOption.AllDirectories, frm as WinForm.Form)

然后就可以使用窗口了
frm.controls("label1").text = io.Path.Combine(path, FindFileData.cFileName)

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


加好友 发短信
等级:狐神 帖子:5061 积分:13092 威望:0 精华:0 注册:2014/5/15 21:34:00
  发帖心情 Post By:2019/8/23 10:09:00 [只看该作者]

谢谢!那函数调用时,EnumerateFiles(“c:\”,"",forms("窗口1")),标签名不是“label1”,是不是也要添加一个参数。

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110738 积分:563610 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/8/23 10:28:00 [只看该作者]


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


加好友 发短信
等级:狐神 帖子:5061 积分:13092 威望:0 精华:0 注册:2014/5/15 21:34:00
  发帖心情 Post By:2019/8/23 10:42:00 [只看该作者]

添加参数后显示,应为“optional”。不好添加参数?为何?

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110738 积分:563610 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/8/23 10:51:00 [只看该作者]

那就到其它ByVal Optional 参数的前面

Public Function EnumerateFiles(ByVal path As String, frm as WinForm.Form, ByVal Optional searchPattern As String = "*.*", ByVal Optional searchOption As IO.SearchOption = IO.SearchOption.AllDirectories)

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


加好友 发短信
等级:狐神 帖子:5061 积分:13092 威望:0 精华:0 注册:2014/5/15 21:34:00
  发帖心情 Post By:2019/8/23 12:23:00 [只看该作者]

不行呀,显示没有为frm指定参数。

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110738 积分:563610 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/8/23 13:34:00 [只看该作者]

写了什么代码?

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


加好友 发短信
等级:狐神 帖子:5061 积分:13092 威望:0 精华:0 注册:2014/5/15 21:34:00
  发帖心情 Post By:2019/8/23 16:24:00 [只看该作者]

<DllImport("kernel32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto, SetLastError:=True)> _
Public Function FindFirstFile(ByVal pFileName As String, ByRef pFindFileData As WIN32_FIND_DATA) As IntPtr
End Function
<DllImport("kernel32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto, SetLastError:=True)> _
Public Function FindNextFile(ByVal hndFindFile As IntPtr, ByRef lpFindFileData As WIN32_FIND_DATA) As Boolean
End Function
<DllImport("kernel32.dll", SetLastError:=True)> _
Public Function FindClose(ByVal hndFindFile As IntPtr) As Boolean
End Function

<Serializable, StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto), BestFitMapping(False)> _
Public Structure WIN32_FIND_DATA
Public dwFileAttributes As IO.FileAttributes
Public ftCreationTime_dwLowDateTime As UInteger
Public ftCreationTime_dwHighDateTime As UInteger
Public ftLastAccessTime_dwLowDateTime As UInteger
Public ftLastAccessTime_dwHighDateTime As UInteger
Public ftLastWriteTime_dwLowDateTime As UInteger
Public ftLastWriteTime_dwHighDateTime As UInteger
Public nFileSizeHigh As UInteger
Public nFileSizeLow As UInteger
Public dwReserved0 As Integer
Public dwReserved1 As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Public cFileName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=14)> _
Public cAlternateFileName As String
End Structure

Public Function EnumerateFiles(ByVal path As String,ByVal frm as WinForm.Form,ByVal lab1 as String,ByVal Optional searchPattern As String = "*.*", ByVal Optional searchOption As IO.SearchOption = IO.SearchOption.AllDirectories)

Dim hFind As IntPtr = -1
Dim FindFileData As WIN32_FIND_DATA = Nothing

hFind = FindFirstFile(IO.Path.Combine(path, searchPattern), FindFileData)
If hFind <> -1 Then
    
    Do
        If FindFileData.cFileName.Equals(".") OrElse FindFileData.cFileName.Equals("..") Then Continue Do
        
        If  searchOption = io.SearchOption.AllDirectories AndAlso ((FindFileData.dwFileAttributes And io.FileAttributes.Directory) = io.FileAttributes.Directory) Then
            'output.show(io.Path.Combine(path, FindFileData.cFileName))
            EnumerateFiles(io.Path.Combine(path, FindFileData.cFileName))
        Else
            

frm.controls(lab1).text = io.Path.Combine(path, FindFileData.cFileName)


        End If

    Loop While FindNextFile(hFind, FindFileData)
    FindClose(hFind)
    
End If

End Function


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  10楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110738 积分:563610 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/8/23 16:31:00 [只看该作者]

外部是怎么调用的?

 回到顶部
总数 14 1 2 下一页