When the button is clicked, I want the file to be opened.
The file will be in the same directory as the visual basic project.
Therefore, I need the code to open the file using "app.Path".
Any solutions?

Recommended Answers

All 5 Replies

it's simple

Open App.Path & "/file name" For Input as #1

"file name" is your name of file

you mast have BackSlash before file name

No no guyz.... I literally want the file to be opened in windows when I click the button.

Put backslash before the name of file in App.path..

What you want to do is somewhat difficult with the native functions in VB6. Using the windows api functions however are much more flexible. Here's an example to open a text file just by passing the path to the file. You should be able to adapt it to your needs.

Option Explicit
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

Const SW_SHOW = 5

Private Sub Command1_Click()
    Dim Filename, MyPath As String
    Filename = "test.txt"
    MyPath = App.Path & "\" & Filename
    ShellExecute hwnd, "open", MyPath, vbNullString, App.Path, SW_SHOW
End Sub
commented: Perfect +12

Perfect tinstaafl!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.