How to open a file in VB6 using app.Path?-VBForums
Results 1 to 8 of 8

Thread: How to open a file in VB6 using app.Path?

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    41

    How to open a file in VB6 using app.Path?

    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?

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,268

    Re: How to open a file in VB6 using app.Path?

    Dim intFile As Integer
    intFile = FreeFile
    Open App.Path + "\myTextFile.txt" For Input As intFile
    strData = Input(LOF(intFile), intFile)
    Close intFile

    OR

    selfile = App.Path + "\myTextFile.txt"
    Open selfile For Input As #1 ' Open file for input.
    Do While Not EOF(1) ' Check for end of file.
    Line Input #1, myLine1 ' Read line of data.
    myWholeLine = myWholeLine & myLine1
    Loop
    Close #1

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,139

    Re: How to open a file in VB6 using app.Path?

    You really should use & rather than + when combining strings
    Code:
    Open App.Path & "\myTextFile.txt" For Input As intFile

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    41

    Re: How to open a file in VB6 using app.Path?

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

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,268

    Re: How to open a file in VB6 using app.Path?

    @DM--I know....bad old habit.....thx for the reminder.....

    @Skate...use the Shell command

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,268

    Re: How to open a file in VB6 using app.Path?

    Like:

    Shell app.path & "\yourFileName.exe", vbNormalFocus

    You are not OPENING a file then, you are RUNNING (or executing) one.

    If you NOT running an executable file (.exe, bat, etc), but want to open, say, a Word Document (.doc, .docx, etc), you would NOT use my example. Please be a bit more explicit on what you are actually trying to do...what kind of file do you want to 'open' (sic)

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,268

    Re: How to open a file in VB6 using app.Path?

    I saw your other thread...why didn't you just answer my question in the previous post...

    Here is how you can do it...

    Shell "c:\windows\system32\xpsrchvw.exe " & App.Path & "\yourfilename.xps"

    I am using Win7...xpsrchvw.exe is found in the system32

    On XP OSs, you can use xpsviewer.exe instead (also found in system32 directory)

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    22,887

    Re: How to open a file in VB6 using app.Path?

    use shellexecute api, will open in the default program for file type, assuming there is one, not all XP machines have an installed application for opening .xps
    i use freeopener to open .xps, as the microsoft .xps reader failed to install correctly

    many examples of shellexecute in this forum
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.