VB 6.0,请用户输入并打开文件夹

时间:2019-02-06 18:25:55

标签: vb6

我想从用户那里得到2个输入并打开文件夹

假设我们有几个目录,例如G:\ s \ ABC-123 \ XYZ-001 我想从用户那里接受2个输入,用户将在不同的文本框中输入123和001,然后打开文件夹。 G:\ s \ ABC-(字符串)\ XYZ-(字符串) 字符串是用户输入的内容。

我已经在互联网上获得了此代码,你们能帮我吗?

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Function pathOfFile(fileName As String) As String
    Dim posn As Integer
    posn = InStrRev(fileName, "\")
    If posn > 0 Then
        pathOfFile = Left$(fileName, posn)
    Else
        pathOfFile = ""
    End If
End Function
Private Sub Command1_Click()
    Dim myPath As String
    myPath = "D:\Dani\result.png"
    ShellExecute 0, vbNullString, pathOfFile(myPath), vbNullString, vbNullString, 1
End Sub

1 个答案:

答案 0 :(得分:2)

假设您的表单上有2个文本框控件,那么您面临的挑战就是如何组合路径。请尝试以下操作:

Private Sub Command1_Click()
    Dim myPath As String
    myPath = "G:\s\ABC-" & Text1.Text & "\XYZ-" & Text2.Text
    ShellExecute 0, vbNullString, pathOfFile(myPath), vbNullString, vbNullString, 1
End Sub