|
-
Dec 12th, 2006, 10:14 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Opening file
I was just wondering,
how can I right-click a file and open it with my VB program?
For example a txt file, and place it in a testbox.
thnx
-
Dec 12th, 2006, 10:17 AM
#2
Re: Opening file
Right click a file from where? A listbox or something from within your program or from Windows Explorer?
-
Dec 12th, 2006, 10:21 AM
#3
Thread Starter
Hyperactive Member
Re: Opening file
just from windows explorer
-
Dec 12th, 2006, 10:56 AM
#4
Thread Starter
Hyperactive Member
Re: Opening file
doesn't VB have a standard option for that?
-
Dec 12th, 2006, 11:14 AM
#5
Re: Opening file
 Originally Posted by Private_sub
doesn't VB have a standard option for that?
You are probably talking about the Common Dialog control, but I've never used a right mouse click with that before.
If you are referring to the Common Dialog, then a quick example would be pretty easy to whip up. Does this work for you?
VB Code:
Private Sub Command1_Click()
With CommonDialog1
.CancelError = False
.InitDir = "c:\"
.Filter = "Text Files (*.txt)|*.txt|"
.ShowOpen
End With
Open CommonDialog1.FileName For Input As #1
Text1.Text = Input(LOF(1), 1)
Close #1
End Sub
-
Dec 12th, 2006, 11:20 AM
#6
Thread Starter
Hyperactive Member
Re: Opening file
i know the common dialog thing.
what i mean is right-clicking a file(in Windows Explorer), then Open with... and then my .exe
if you don't know how it works, please don't waste any time on it.
-
Dec 12th, 2006, 12:36 PM
#7
Re: Opening file
I think he means a Context Menu in explorer so that when he clicks a file it can open it in hes program...
in your form_load you can do... msgbox command$ & " - thats the path of this file"
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.

-
Dec 12th, 2006, 12:42 PM
#8
Re: Opening file
Do you mean as in (In explorer) Tools > Folder Options > File Types > Advanced > New. ?
Last edited by schoolbusdriver; Dec 12th, 2006 at 01:09 PM.
-
Dec 13th, 2006, 05:12 AM
#9
Thread Starter
Hyperactive Member
Re: Opening file
some1uk03's code sort of works, but I get "C:\file.txt" instead of C:\file.txt
So when I try to load it into my form, it doesn't work because of the ""s
-
Dec 13th, 2006, 05:45 AM
#10
Thread Starter
Hyperactive Member
Re: Opening file
I can use this:
var = Replace(var,""", "")
But the """ is not working, i've done it before with something like ascii.
I forgot how to use it, when i know that, it's gonna work.
-
Dec 13th, 2006, 05:46 AM
#11
Re: Opening file
to do what you are asking you will need to edit the registry for the windows shell to add your program to the types of files you want to associate to your program
the filetype keys are in the HKCR section of the registry,
make sure to back up the registry before you edit it
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
-
Dec 13th, 2006, 05:48 AM
#12
Re: Opening file
var = Replace(var,""", "")
try
VB Code:
var = Replace(var,"""", "")
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
-
Dec 13th, 2006, 05:51 AM
#13
Thread Starter
Hyperactive Member
Re: Opening file
That sounds pretty cool, but how can i add new filetypes to the registry?
I don't get all the binary stuff
-
Dec 13th, 2006, 05:53 AM
#14
Thread Starter
Hyperactive Member
Re: Opening file
Thanx Westconn1!
The """" works great!
-
Dec 13th, 2006, 06:08 AM
#15
Thread Starter
Hyperactive Member
Re: Opening file
If anyone is interested, here is the code I made:
VB Code:
Dim fileLocation As String
Dim orLoc As String
Private Sub Form_Load()
If Not Command$ <> vbNullString Then
Text1.Text = "Please begin here"
Else
Text1.Text = "An error has occured, please check if your file is a working text-file."
End If
On Error Resume Next
orLoc = Command$
fileLocation = Replace(orLoc, """", "")
Open fileLocation For Input As #1
Text1.Text = Input(LOF(1), 1)
Close #1
End Sub
-
Dec 13th, 2006, 07:06 AM
#16
Re: [RESOLVED] Opening file
using on error resume next can cause probelms with debugging, better to use an error handler
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
-
Dec 13th, 2006, 07:34 AM
#17
Thread Starter
Hyperactive Member
Re: [RESOLVED] Opening file
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
|