这是我的代码(注意这是由朋友给出的):
Private Sub browse_Click() Dim textfile As String textfile = Space(255) GetFileNameFrombrowseW Me.hWnd,StrPtr(sSave),255,StrPtr("c:\"),StrPtr("txt"),StrPtr("Apps (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All files (*.*)" + Chr$(0) + "*.*" + Chr$(0)),StrPtr("Select File") Text1 = Left$(textfile,lstrlen(textfile)) End Sub
基本上后来我编辑了所选的文本文件,所以稍后我只是在我的函数中使用textfile来调用它.但是我得到了一条未找到的路径,所以我觉得我做错了什么.
提前致谢.
解决方法
从
here起
我找到了这个代码并运行它.
Private Const VER_PLATFORM_WIN32_NT = 2 Private Type OsveRSIONINFO dwOsversionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersion@R_472_4045@ion As OsveRSIONINFO) As Long Private Declare Function GetFileNameFrombrowseW Lib "shell32" Alias "#63" (ByVal hwndOwner As Long,ByVal lpstrFile As Long,ByVal nMaxFile As Long,ByVal lpstrInitialDir As Long,ByVal lpstrDefExt As Long,ByVal lpstrFilter As Long,ByVal lpstrTitle As Long) As Long Private Declare Function GetFileNameFrombrowseA Lib "shell32" Alias "#63" (ByVal hwndOwner As Long,ByVal lpstrFile As String,ByVal lpstrInitialDir As String,ByVal lpstrDefExt As String,ByVal lpstrFilter As String,ByVal lpstrTitle As String) As Long Private Sub Form_Load() 'KPD-Team 2001 'URL: http://www.allapi.net/ 'E-Mail: [email protected] Dim sSave As String sSave = Space(255) 'If we're on WinNT,call the unicode version of the function If IsWinNT Then GetFileNameFrombrowseW Me.hWnd,StrPtr("Text files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All files (*.*)" + Chr$(0) + "*.*" + Chr$(0)),StrPtr("The Title") 'If we're not on WinNT,call the ANSI version of the function Else GetFileNameFrombrowseA Me.hWnd,sSave,"c:\","txt","Text files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All files (*.*)" + Chr$(0) + "*.*" + Chr$(0),"The Title" End If 'Show the result MsgBox sSave End Sub Public Function IsWinNT() As Boolean Dim myOS As OsveRSIONINFO myOS.dwOsversionInfoSize = Len(myOS) GetVersionEx myOS IsWinNT = (myOS.dwPlatformId = VER_PLATFORM_WIN32_NT) End Function
从我可以告诉你GetFileName函数看起来正确所以我猜这个问题就在于此
Text1 = Left$(textfile,lstrlen(textfile))
用它来检查
MsgBox "(" & Text1 & ")-(" & textfile & ")"
确保你从Left $和lstrlen获得预期的结果
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。