Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Process class help

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Resolved [RESOLVED] [2005] Process class help

    well wat im trying to do is use an array with the process class so i can start and control multiple processes. anyone got an example of this? i tryed it like...

    VB Code:
    1. If open.FileName = Nothing Then Exit Sub
    2.         dim loc as string = open.filename
    3.         amount = TextBox1.Text - 1
    4.         Dim p(amount) As Process
    5.         'ReDim p(0 To amount)
    6.         For i As Long = 0 To amount
    7.             p(i).StartInfo.FileName = loc
    8.             p(i).Start()
    9.         Next

    it gives me the error "Object reference not set to an instance of an object.", any help?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,458

    Re: [2005] Process class help

    The Process class is a reference type. You have created an array full of Process references that are all null. You have to create a Process object and assign it to an element before you can use that element. An array is just basically a bunch of variables. You can't use a variable of any reference type without creating an object, so the same goes for array elements.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2005] Process class help

    Quote Originally Posted by jmcilhinney
    The Process class is a reference type. You have created an array full of Process references that are all null. You have to create a Process object and assign it to an element before you can use that element. An array is just basically a bunch of variables. You can't use a variable of any reference type without creating an object, so the same goes for array elements.
    so how would i accomplish wat im trying to do?

  4. #4
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: [2005] Process class help

    I think it's just:

    VB Code:
    1. If open.FileName = Nothing Then Exit Sub
    2.         dim loc as string = open.filename
    3.         amount = TextBox1.Text - 1
    4.         Dim p(amount) As Process
    5.         'ReDim p(0 To amount)
    6.         For i As Long = 0 To amount
    7.             p(i) = New Process
    8.             p(i).StartInfo.FileName = loc
    9.             p(i).Start()
    10.         Next
    Age - 15 ::: Level - Advanced
    If you find my post useful please ::Rate It::


  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,458

    Re: [RESOLVED] [2005] Process class help

    The easiest way is:
    VB Code:
    1. For i As Integer = 0 To p.GetUpperBound(0) Step 1
    2.     p(i) = Process.Start(loc)
    3. Next i
    You would only need to use a ProcessStartInfo object if the you needed to specify more than file name and commandline arguments.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width