Drag and drop parameter

J

John

Howdy,

I havn't been using VB.NET just a whole lot, and am finally making the
transistion from VB6 to dotnet. (Yeah it is pretty sad, I know.)

Anyhow, I have created several apps in vb6 that I allowed the user to drag
and drop a file onto the executable. The executable would grab the path and
filename of the dropped file and store it in a variable. I could then use
the variable to access and manipulate the file.
I also used the same thing to use execution parameters for the executables.
I simply declared a variable, then in the form load routine I set the
variable = to the command

something along the lines of this
Dim DXF_File
Private Sub Form_Load()

DXFFile = Command

If the user dropped the file "C:\howdy.txt" onto the executable then the
value of the variable DXFFile would be "C:\howdy.txt"

How the hell do I do that in VB.Net? I have looked in the documentation and
couldn't figure out what the heck to look for.

If you could offer some direction I would appreciate it.

Thanks,

John
 
C

ClayB

In Form.Load, you can use the Shared variable Environment.CommandLine
to access the exe name in double quotes followed by a space and then
the dropped file path.

If Environment.CommandLine.Length > 0 Then
Dim i As Integer = Environment.CommandLine.IndexOf(""" ")
If i > - 1 Then
Dim pathName As String = Environment.CommandLine.Substring((i +
2))
MessageBox.Show(pathName)
End If
End If

====================
Clay Burch
Syncfusion, Inc.
 
G

Guest

John,

Try this, add this for the command equiv from vb6:


'save command line arguments passed to the application
For Each s As String In My.Application.CommandLineArgs
StartupCommand = s.ToLower
Exit For
Next


StartupCommand is now sort of the same as command from vb6 and has the file
name.

My.Application.CommandLineArgs has the info and its not the same as vb6.

Tom
 
J

John

I ended up going with this one. Worked like a charm.

Thanks for the input, I was getting frustrated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top