Code to open file automatically by association

I am looking for the code to open an associated file automatically. For example, I have created a VB application which opens and read files with the extension .PAG

When a user double-clicks on a file with the extension of .PAG in Windows Explorer, I want the VB application to open that particular file after starting.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If its a new extention, simply double click it in windows explorer.
windows asks what to use.
browse to your app, check the "always use this program" and OK.

If you want to do this programattically, use the api viewer to add registry funcs.
Go HKey_CLASSES_Root and find your key(s), simply emulate this.

mcdonald_gAuthor Commented:
The code I am looking for is strictly VB syntax. I already have the association set in Windows Explorer.

I need the VB code to open the file that was double-clicked in Explorer.

Right now when I double-click on a filename with an extension of .PAG, my VB app launches but it doesn't open the file. I need to plug in code to open the file after the app starts.
You will need to get the command line arguments in the form create of your application. This will give you the filename of the double clicked file in windows explorer. Thus this can be used to read in the file.

When applications are double clicked in windows explorer they launch the associated file passing the filename of the double clicked file.

The 'Command' function returns what ever command line parameters have been passed to your application. In this case there will be one which is the file name.

Private Sub Form_Load()
Dim FileName As String
 FileName = Command
 MsgBox FileName
 '....load the text file given file name
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
When the program starts, check the value of the Command function.  It should be the filename if your program was started from clicking on an associated file.
mcdonald_gAuthor Commented:
Thanks a lot! It worked.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.