Okay, how can I make it so I can open a file WITH my program? It's a simple editor, how do I make it accept files?
Printable View
Okay, how can I make it so I can open a file WITH my program? It's a simple editor, how do I make it accept files?
You probably need to use some API and registering the ext of your files in the reg . Very easy way is to use InstallSheild . It has the option to add this functionality while installing your app . It does all the work for you .
I'm not even worried about registering my file, I want to know how my program can open a file if I select it and click open with...Quote:
Originally posted by Pirate
You probably need to use some API and registering the ext of your files in the reg . Very easy way is to use InstallSheild . It has the option to add this functionality while installing your app . It does all the work for you .
you have to tell windows to pass the path to app and heres how you get it
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim strArgs() As String Dim I As Integer strArgs = Environment.GetCommandLineArgs() 'strArgs(0) the path to the exe 'strArgs(1) is the first arg 'strArgs(2) is the second arg ect. For I = 0 To UBound(strArgs) MsgBox(strArgs(I)) Next End Sub End Class
Thanks, I can get it so I can right click and open files right into my program, however if I run my program normally, I get an error.
The 2nd arguement within the array is always the file's name and location, if I just run the program it will give me the location of my program's .exe. So as is, I can open other files into my program, I CANNOT just open the program by itself.
I have an If statement on my main form which declares fileInfo so I can get the extension, and then I used an if statement to check, if it's an exe, then it just opens, otherwise it opens the file into the text box.
VB Code:
Dim fileInfo As New IO.FileInfo(strArgs(1))
This works perfectly, except when the program is run normally, then it says this error:
I'm confused, how can I make this work, I figured a simple if statemenet to check to see if the program is either being run or was given arguements.Code:Index was outside the bounds of the array.
You should encapsulate the handling of any arguments within an If..Then block to first see if there are any arguments. strArgs(1) assumes there are arguments passed in which when you run it normally there aren't.
VB Code:
Dim strArgs() As String Dim I As Integer strArgs = Environment.GetCommandLineArgs() If strArgs.Length>0 then 'Handle arguments here Dim fileInfo As New IO.FileInfo(strArgs(1)) End If
opps
nm thanks