Double Click Me All The Way To Heaven
May 18, 2009 2:11 PM   Subscribe

Visual Basic 6 Filter: Double click on file, my program opens that file. How do I do it?

Quick Summary: I have a program that I have written in VB6. I would like to associate this program with a file extension. When I double click on a file with this extension (BRD) I want my program to automatically open with that file loaded.

I was able to make this work on the command line. If I type
"myexecutable.exe openthisfile.brd"
then my program opens that file. I used this code...

Private Sub Form_Load()
If ((Command <> "") And (FileExists(Command))) Then
OpenSoundBoard(Command)
End If
End Sub

I am not concerned with registering my program with Windows. I would like, however, to always open BRD files with my program. I have done this without using the registry by telling Windows to always use myprogram.exe to open BRD files. However, when I double click on a BRD file myprogram.exe throws an error:

Run-time Error '52':

Bad file name or number


I don't know the terminology for this problem, so searching for an answer has been unfruitful. I am no expert in VB, but I know enough to get myself into trouble - as I have done here. Any help would be appreciated. Thanks MeFites!
posted by Brettus to Computers & Internet (6 answers total)
 
You have to set up a filetype association.

The easiest way to do that is to right-click the file and select "open with" plus appropriate choice from the resulting menu. You haven't said what OS you're using, so I'm assuming WinXP here: the menu choice is "Choose Program".

It'll pop up a menu permitting you to select an app; you use it to find yours. Then make sure that the "Always use this application" check mark is selected.
posted by Chocolate Pickle at 2:16 PM on May 18, 2009


If you've already done that and it didn't work, then the problem is that Windows didn't create the right command line string. Open the explorer, and under the "tools" menu, select "folder options". Choose the "filetypes" tab, and scan down to find yours. Select it, then click "Advanced", and mess around there; it's pretty clear how it works.
posted by Chocolate Pickle at 2:18 PM on May 18, 2009


I am not concerned with registering my program with Windows.

Is there a specific reason why you don't want to use the registry for this? Granted, the Windows registry has its problems, but that is the usual way to do it.
posted by trip and a half at 2:39 PM on May 18, 2009


It's going to be a program just for me and I don't want to go through the hassle of learning how to work the registry for such a small thing.

Skip this section if you don't want to learn about the program: I do a podcast with friends and we heavily use sound effects. Instead of using playlists and media players for this, we wanted something that would be a bit more responsive. I have created a 5 x 4 grid of buttons that you can assign WAV files. You can save these different boards to files and have multiple sound boards available to you at once. I found many things available that did this, but all were muddied up with features that I didn't want.

If anyone wants this program, I will be happy to supply the executable to them.

I have figured out the issue with the help of Chocolate Pickle - the issue is that Windows was putting quotes around my file name, which was causing problems. Here is the fixed code...

Private Sub Form_Load()
Dim OpenFile as String

If (Command <> "") Then
OpenFile = Replace(Command, """", "")
If (FileExists(OpenFile)) Then
OpenSoundBoard(OpenFile)
End If
End If

End Sub


BTW - Is there a way to quote code on here?
posted by Brettus at 2:48 PM on May 18, 2009


The quotes are actually a pretty good idea, because without them some filenames won't parse correctly. But if this is just a private utility for you, and you can make sure your data files don't have unusual names (i.e. don't contain spaces or unusual characters) then removing the quotes is fine.

Still, it would be better to make your app (in VB) check for the quotes and remove them if they're there and paired.
posted by Chocolate Pickle at 4:29 PM on May 18, 2009


Actually, you can use file names with spaces in them with this solution. Since the quotes are a part of the string to begin with, VB is considering them as part of the path - which is invalid. Removing them and placing the results in another string still leads you down paths and filenames that contain spaces, at least - this has been the behavior so far.

Either way - this works great. Thanks a ton for helping me out.
posted by Brettus at 5:40 PM on May 18, 2009


« Older Flying around Brazil: airpass?   |   Feminist sci-fi novel featuring psychic hunting... Newer »
This thread is closed to new comments.