Results 1 to 5 of 5

Thread: Opening a File from a FIleListBox, PLEASE RESPOND

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Posts
    20

    Arrow

    I have made a program with one form containing a DriveListBox, a DirListBox, and a FileListBox. What I want to know is how to make it so when a double click on a file in the file list box it opens that file.
    I'd appreciate any help on this matter, thank you.

  2. #2
    Member
    Join Date
    Mar 2000
    Location
    Mentor,Oh,US
    Posts
    33

    Cool

    Here, try this... this is assuming you are using notepad.

    Code:
      Shell ("C:\Windows\notepad.exe ") & (File1.FileName)
    Don't forget this is just a sample and may vary on the program. And you must obviously change the current Drive & Dir for it to even SEE the file.
    If at first you DO succeed, don't look too astonished!
    -deadBird
    =================

  3. #3
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    if you are using a text box in your own program use this:
    Code:
    Dim FileName As String
    
    Private Sub Command1_Click()
    
    FileName = dir1.path & "\" & file1.filename
        F = FreeFile
        Open FileName For Input As #F
        Text1.Text = Input$(LOF(F), F)
        Close #F
    End Sub
    
    Private Sub file1_dblClick()
    
         call Command1_Click
    
    End Sub
    <removed by admin>

  4. #4
    Guest
    Code:
    Public 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
    
    Public Const SW_SHOWNORMAL = 1
    
    
    Private Sub Dir1_Change()
        File1.Path = Dir1.Path
    End Sub
    
    Private Sub File1_DblClick()
    
        If Len(Dir1.Path) <= 3 Then d = Dir1.Path & File1.filename
        If Len(Dir1.Path) > 3 Then d = Dir1.Path & "\" & File1.filename
        ShellExecute Me.hwnd, vbNullString, d, vbNullString, "c:\", SW_SHOWNORMAL
    
    End Sub

  5. #5
    Guest
    Assuming that you have files other than Text files, use the following code to open them.
    Code:
    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
    
    Private Sub File1_DblClick()
        ShellExecute hwnd, "open", File1, "", "", 1
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width