Griffin
Griffin

Reputation: 842

Problems with For... Next Statements in Vb. Net

This is my code so far


        For intArrayCheck = 0 To 16
            foo = sender.name
            If foo = strShipsLocationArray(intArrayCheck) Then
                MessageBox.Show("You got a ship down!")
                sender.backcolor = Color.Red
            End If
        Next

What I want the code to do is if foo is not equal to any strings in strShipLocationsArray then


        sender.backcolor = Color.Blue

How do I do this?

Thank you for any help

Upvotes: 0

Views: 167

Answers (2)

moonshadow
moonshadow

Reputation: 89055

Always set it to blue before your loop. That way if it is never set to red during the loop, it'll still be blue afterwards, so the final result will always be as required.

If setting that property has an immediate side effect, use a temporary variable and assign it to sender.backcolor after the loop finishes.

Upvotes: 1

BlackBear
BlackBear

Reputation: 22979

Set it to blue before entering the loop. So if will change If foo=strShipsLocationArray(intArrayCheck), otherwise it will stay blue

Upvotes: 3

Related Questions