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
Printable View
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
Right click a file from where? A listbox or something from within your program or from Windows Explorer?
just from windows explorer
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.Quote:
Originally Posted by Private_sub
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
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.
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"
Do you mean as in (In explorer) Tools > Folder Options > File Types > Advanced > New. ?
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
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.
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
tryQuote:
var = Replace(var,""", "")
VB Code:
var = Replace(var,"""", "")
That sounds pretty cool, but how can i add new filetypes to the registry?
I don't get all the binary stuff :p
Thanx Westconn1!
The """" works great!
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
using on error resume next can cause probelms with debugging, better to use an error handler
Ok, thanx.
I used this for the standard icon etc.:
http://www.vbcodemagician.dk/tips/files_association.htm