当前位置 : 主页 > 编程语言 > c语言 >

Vb6:选择一个文件以便以后通过浏览按钮使用

来源:互联网 收集:自由互联 发布时间:2021-06-24
这是我的代码(注意这是由朋友给出的): 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)
这是我的代码(注意这是由朋友给出的):

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 lpVersionInformation 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 nMaxFile As Long, 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: KPDTeam@Allapi.net
    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(sSave), 255, StrPtr("c:\"), StrPtr("txt"), 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, 255, "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获得预期的结果

网友评论