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

How do I do Process.Start inside a for loop?

P: 1
This is my first application I'm making and I've done fine so far, but know I'm stuck with processing some files to be encoded using lame. I've got a collection of filenames in datagridview, which also shows other info. I'm using a for loop to go through every row and retrieve the filenames for encoding. The first time through the for loop goes fine, but any subsequent loops fail.

Here is my code so far:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  2.         Dim parameters As String = Label7.Text
  3.         Dim infile As String
  4.         Dim outfile As String
  5.         Dim cnt As Integer
  6.         cnt = 0
  7.  
  8.         For Each row As DataGridViewRow In DataGridView1.Rows
  9.             If System.IO.File.Exists(TextBox1.Text + "\" + row.Cells(1).Value.ToString) Then cnt += 1
  10.         Next
  11.         If cnt > 0 Then
  12.             If MsgBox("Do you want to overwrite existing file in the folder?", MsgBoxStyle.OkCancel) = MsgBoxResult.Cancel Then Exit Sub
  13.         End If
  14.         For Each row As DataGridViewRow In DataGridView1.Rows
  15.             infile = " """ + row.Cells(0).Value.ToString() + """"
  16.             outfile = " """ + TextBox1.Text + "\" + row.Cells(1).Value.ToString() + """"
  17.             parameters = parameters + infile + outfile
  18.             Using myProcess As Process = New Process
  19.                 myProcess.StartInfo.FileName = "lame.exe"
  20.                 myProcess.StartInfo.Arguments = parameters
  21.                 myProcess.Start()
  22.                 myProcess.WaitForExit()
  23.             End Using
  24.         Next
  25.     End Sub
Feb 23 '13 #1
Share this Question
Share on Google+
2 Replies


Mikkeee
P: 94
How is this failing? Are you seeing an error? If so, please let us know which line of code is causing the failure and give us the error detail.
Feb 23 '13 #2

zmbd
Expert Mod 5K+
P: 5,397
When you post your error message
Please post the exact title of the error
Please post the exact number if given
Please post the exact text

Often error messages are the same and vary only in the title, number or small variations in the text; thus, having the exact information is most important for trouble shooting.

Additionally, you should perform some basic trouble shooting yourself, such as stepping thru the code in break mode. It is impossible for us to do that kind of work as we do not have your PC sitting in front of us.
Feb 24 '13 #3

Post your reply

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