tags:

views:

107

answers:

2
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

+5  A: 
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.

Kobi
Thanks, it works
Snoob
+2  A: 

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.

Anax
There are many issues with this code: `i` should be `shade`, `re` should probably be `increasingSahde`, and `if increasingSahde then`. I can think of a few more.
Kobi
Thanks, but i am not english, so i just make a random var name :(
Snoob