Vb6:通过浏览按钮选择稍后使用的文件 [英] Vb6: Selecting a file to later be used via a browse button

查看:27
本文介绍了Vb6:通过浏览按钮选择稍后使用的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码(注意这是朋友给的):

Here's my code (note that this was given by a friend):

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

基本上稍后我会编辑所选的文本文件,因此稍后我仅通过在我的函数中使用文本文件来调用它.但是我找不到一条路径,所以我觉得我做错了什么.提前致谢.

Basically later on I edit the text file selected so later I call it just by using textfile in my function. However I get a path not found so I feel like I'm doing something wrong. Thanks in advance.

我想要做的就是选择一个文本文件,然后可以调用它并使用它.

All I want to do is select a text file, then later be able to call it and use it.

推荐答案

来自 这里

我找到了这段代码并运行了它.

I found this code and ran it.

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 函数看起来是正确的,所以我猜问题出在这个

From what I can tell you GetFileName function looks right so my guess the problem is with this

Text1 = Left$(textfile, lstrlen(textfile))

用这个来检查

MsgBox "(" & Text1 & ")-(" & textfile & ")"

确保您从 Left$ 和 lstrlen 获得预期结果

to make sure you are getting the expected result from Left$ and lstrlen

这篇关于Vb6:通过浏览按钮选择稍后使用的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆