Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Value of increment variable jumps in vb.net

$
0
0
Hello Friends,
I got another problem.

I am trying to achieve an AutoHide functionality in my label
So I tried to create a Class Library Project named InformationBar

Just a look at my code :
Imports System.Windows.Forms
Imports System.Drawing

Public Class InformationBar
    Inherits DevComponents.DotNetBar.LabelX

    Dim TimeOut As Integer
    Dim TimerForTimeOut As New Timer
    Dim i As Integer

    Public Property Time_Out() As Integer
        Get
            Return TimeOut
        End Get
        Set(ByVal value As Integer)
            TimeOut = value
        End Set
    End Property


    Private Sub InformationBar_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged

        If Me.Visible = True Then
            AddHandler TimerForTimeOut.Tick, AddressOf TimerForTimeOut_Tick
            TimerForTimeOut.Interval = 1000
            TimerForTimeOut.Start()
        End If

    End Sub

    Private Sub TimerForTimeOut_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
        
        i = i + 1

        If i = TimeOut Then
            i = 0
            Me.Visible = False
            TimerForTimeOut.Stop()
        End If

        Form1.Label1.Text = i
        Form1.Label2.Text = TimeOut
    End Sub

End Class


Here Time_Out Property is Created. For the value of that Variable TimeOut is declared
i is another variable which increments by 1 everytime the timer is tick

This code should show a label for some time given by the user while a button is clicked and after that it should be vanished
While running this code :
If I give the value of timeOut = 10
then I click on the button the label is shown for 10 seconds after that it is hidden
Then I click the button Second time then the label should be shown again for 10 seconds but it is being shown for 7 to 8 seconds only and then again........the time of label shown decreases

I think this code should work but it didnt
It does not give me any error
So I decided that there should be some problem with variable i
I kept breakpoints but still I could not find any Problems
So I placed a label on the form and examined the values of i on each Tick of Timer

Here I got some strange results
the value of i when the button is clicked for the first time : 1,2,3,4,5,6,7,8,9,10.
the value of i when the button is clicked for second time : 1,3,5,7,9,1
the value of i when the button is clicked third time : 1,2,4,6,8,10
fourth time : 6, 10
and so on..........

thanks in advanced

Viewing all articles
Browse latest Browse all 51036

Trending Articles



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