收录日期:2019/10/22 14:26:48 时间:2012-05-01 07:44:00 标签:vb.net
Public Class Form1  
Dim i = 0  
Dim re = True  
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)   Handles Timer.Tick  
    If i = 225 Then  
        re = False  
    ElseIf i = 0 Then  
        re = True  
    End If  
    If re = True Then  
        i += i  
    ElseIf re = False Then  
        i -= i
    End If  
    color1.BackColor = Color.FromArgb(i, i, i)  
End Sub  
End Class  

In this code, i want the label from black to white and then from white to black. I set the re var to indicate whether it is white, then i will reduce until the color to black. => Not works

i += i 

Should be:

i += 1

i starts at 0, so you keep adding 0+0 and never get anywhere.
Also, RGB colors go all the way to 255, not 225, but you would have seen that one.

First of all, make sure you have enabled timer Timer somewhere else in your code. Also, do what Kobi said, change i += i to i += 1.

What's also important is to start using Option Strict On, Option Explicit On and declaring the types of your variables:

Dim i As Integer = 0  
Dim re As Boolean = True  

This is the first step to improve your code quality.