开发者

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

开发者 https://www.devze.com 2023-02-14 20:52 出处:网络
This is my code so far For intArrayCheck = 0 To 16 foo = sender.name If foo = strShipsLocationArray(intArrayCheck) Then

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 strSh开发者_C百科ipLocationsArray then


        sender.backcolor = Color.Blue

How do I do this?

Thank you for any help


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消