• Log in or sign up for an account here: https://www.sythe.org/login

Using windows explorers "Open With"!

Darthatron

Massive Troll

Retired Sectional Moderator
Visual Basic Programmers
Joined
May 22, 2006
Sythe Gold
0
Messages
1,612
Age
35
Location
The internet.
Alright, have you ever wondered how to open a file in your application directly from Windows Explorer? Well, I'll show you how, using the "Command$" command.

It's just a few lines of code. I'll explain it as best I can.

In General Declarations put this line of code...
Code:
Dim FileLocationName As String
That just gives us a string to hold the File Location. Pretty basic stuff.

Next in the Form_Load() section of your code put this...
Code:
    If Command$ <> "" Then
        FileLocationName = Replace(Command$, """", "")
        'Do Events
    End If

Alright, so the "Command$" command loads the Location of the file if "Open With" is used in Windows Explorer. I'm not 100% sure how it works but, I know it loads the location. ;) But the downfall is, it loads it with quotation marks. ("").

So in order to remove those we use the "Replace" command. Which looks for a certain string inside the String you choose. Now, to find "'s we put (""""), we have to put 2 lots of quotation marks.

Next we merely replace them with "" or nothing.

Where I put "'Do Events" is where you would put the events you want to use the file with.

I hope I have explained this enough. Have fun.
 
wait, whats this supposed to do?
 
I made a tutorial on this a while ago.


You should also show more functions of "Command" ($ means string. (For the people that didn't know))

Such as the Command line options when loading a program, and other such examples...


If you make a shortcut to your program, and place it on the desktop, such as
Code:
"C:\...\Desktop\half-life 2 episode two\hl2.exe" -steam -game ep2

The command line options in this case are
-steam
-game



So in your startup routine (Sub Main rather then Form_Load) you could have something similar to this:

Code:
      If InStr(1, Command, "[I]steam[/I]") <> 0 Then Do_Steam = True
      If InStr(1, Command, "[I]game[/I]") <> 0 Then Call RunGame

The above is 100% made up, as an example.


So your example is calling something similar to:
Code:
"C:\...\Desktop\half-life 2 episode two\hl2.exe" "C:\Program Files\Test.File"



@pwnintheface

If you have your own program, with it's own filetype, you can make your program start up by using the "Open with" option with windows explorer.

This will not make your program load that file however.

Darthatron here has shown how to make your program load that file if one has been specified.
 
Runescape Gamblingrunescape gambling
Back
Top