By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,101 Members | 1,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,101 IT Pros & Developers. It's quick & easy.

VB.NET Command Line Arguments

P: 2
I am writing a program that is used to merge data from two different file types; a JBX and a JBN file. In the program there a two list boxes, one to hold the JBX file and one for the JBN. I wanted to add the ability that if a user goes into a folder, selects multiple JBX and JBN files, and opens then, the program would automatically start up and put the file into there appropriate columns. I tried the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.  
  3.         Dim param As String
  4.  
  5.  
  6.         For Each param In System.Environment.GetCommandLineArgs
  7.  
  8.             MsgBox(param)
  9.  
  10.             If param.Substring(param.Length - 3, 3).ToLower = "jbx" Then
  11.                 lstJBX.Items.Add(Path.GetFileNameWithoutExtension(param))
  12.             ElseIf param.Substring(param.Length - 3, 3).ToLower = "jbn" Then
  13.                 lstJBN.Items.Add(Path.GetFileNameWithoutExtension(param))
  14.             End If
  15.  
  16.         Next
  17.  
  18.     End Sub
I added the MsgBox code so that when I ran the program I would be able to see the arguments that were being passed to the program. However, if I select 3 JBX file and 3 JBN files and try to open them, the first message box that appears is the full path of the program which obviously isn't put in one of the list boxes because it has an EXE extension. The second message box that appears is only the full path of the first file (out of the 6) that I selected. It is put into the correct listbox, but it seems that the paths of the other five files are not being passed to the program and I can't figure out why.

The effect I'm trying to achieve is similar to that of Winamp or Window Media Player, in that you select multiple files from outside the program and the program will load and place the names of the files (without the paths) into a playlist (in my case a list box).

Any comments or help will be greatly appreciated. I am running MS VS 2005 Professional Edition on Windows XP SP2.

Thanks,

Dominick
Mar 30 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 5K+
P: 8,434
Seems to me, if you tell Windows to open 6 files it will do so as 6 distinct actions, thus starting (if appropriate) the same program 6 times. When your program is started the 2nd to 6th times, it would need to detect that an instance is already running, and pass the relevant information to it. I believe that's probably how MS Word, WinAmp and so on probably handle it, though I wouldn't put too much money on that.

If your program is not coming up six times, perhaps you have something set up to prevent multiple instances executing?
Apr 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.