-
Dec 24th, 2012, 08:59 AM
#1
Thread Starter
Member
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?
-
Dec 24th, 2012, 09:33 AM
#2
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
-
Dec 24th, 2012, 11:30 AM
#3
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
-
Dec 24th, 2012, 11:41 AM
#4
Thread Starter
Member
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.
-
Dec 24th, 2012, 12:51 PM
#5
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
-
Dec 24th, 2012, 12:56 PM
#6
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)
-
Dec 24th, 2012, 03:49 PM
#7
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)
-
Dec 24th, 2012, 04:53 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|