Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Understanding the Else If statement

$
0
0
Hello all!

I come from a PHP background which I have found to be quite similar to VB. I am having a little trouble using an Else If statement though, I'm just messing around trying to get to grips with it all right now. Here is the trouble I'm having:

Code:

        For Each proc As Process In Process.GetProcesses
            If proc.ProcessName = "notepad" Then
                MsgBox("Process is running")
            End If
        Next

Basically, if notepad is running, when the button is pressed it displays a popup saying "Process is running", all I want to do is display a popup saying "Process isn't running" if it isnt, now, I thought this would be the most simple part of it all, this is what I expected to write:

Code:

        For Each proc As Process In Process.GetProcesses
            If proc.ProcessName = "notepad" Then
                MsgBox("Process is running")
            Else
                MsgBox("Process isn't running")
            End If
        Next

If notepad is running I get the "Process is running" popup followed by an infinite number of "Process isn't running" popup boxes, if notepad isnt running I just get the infinite "Process isn't running" popups. I have tried a few various things but cant get my head around this! I know it should be quite simple!

Do i have to set a new if statement? such as

Code:

        For Each proc As Process In Process.GetProcesses
            If proc.ProcessName = "notepad" Then
                MsgBox("Process is running")
            ElseIf XXX Then
                MsgBox("Process isn't running")
            End If
        Next

Any help would be much appreciated!
Tom.

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>