PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2008 MsgBox when process isnt found?-VBForums
Results 1 to 4 of 4

Thread: MsgBox when process isnt found?

  1. #1

    Thread Starter
    Banned
    Join Date
    Aug 2009
    Posts
    333

    MsgBox when process isnt found?

    How would I change the following code so that if the process isnt found, it will pop up a msgbox
    Code:
       Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName(TextBox1.Text)
            For Each p As Process In pProcess
                p.Kill()
            Next

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,817

    Re: MsgBox when process isnt found?

    Hi,

    VB.NET provides three keywords try, catch and finally to do exception handling. The try encloses the statements that might throw an exception whereas catch handles an exception if one exists. The finally can be used for doing any clean up process.

    The general form try-catch-finally in VB.NET is shown below.

    vb Code:
    1. Try
    2. ' Statement which can cause an exception.
    3. Catch x As Type
    4. ' Statements for handling the exception
    5. Finally
    6. End Try 'Any cleanup code
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,892

    Re: MsgBox when process isnt found?

    pProcess is an array, right? It contains all the processes with that name, right? What about that array would indicate that there were no processes with that name?

  4. #4
    Member
    Join Date
    Apr 2009
    Posts
    37

    Re: MsgBox when process isnt found?

    try this~
    Code:
        Public Sub CheckProcess(ByVal ProcessName As String)
            If ProcessName = String.Empty Then
                Exit Sub
            End If
            For Each Checkp As Process In Process.GetProcessesByName(ProcessName)
                If Checkp.HasExited = False Then
                    MsgBox("Process FOUND")
                    Exit Sub
                End If
            Next
            MsgBox("Process NOT FOUND.")
        End Sub

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width