Click here to Skip to main content
14,735,594 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello can someone help me out how to create this feature:
My.Settings.Time = 10 ( time integer user 10)

And i want when form load Timer1 is starting and reading from My.Settings.Time value
And to start countdown from that value to 0. When value become 0 to show msgbox(work).

Thats what i'm trying to do. To read from My.Settings the value and countdown from it.

What I have tried:

Form1_load
Timer1.Start()

Timer1_Tick:
<pre>Try
            Timer1.Interval = My.Settings.Time
            If My.Settings.Time = 0 Then
                MsgBox("Work")
                Timer1.Stop()
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
Posted
Updated 24-Sep-20 9:56am
Comments
ZurdoDev 24-Sep-20 13:45pm
   
Where are you stuck?
diablo22 24-Sep-20 13:46pm
   
i cannot manage to do it, my code above not work at all
ZurdoDev 24-Sep-20 13:48pm
   
Debug the code and find a specific issue you need help with.
diablo22 24-Sep-20 14:03pm
   
it doesnt countdown the value from settings
ZurdoDev 24-Sep-20 14:07pm
   
I don't see any code that will countdown. Maybe you mean the timer does not fire?
diablo22 24-Sep-20 14:11pm
   
timer is starting, but i cannot make to read from my.settings.time value and start countdown from 10 - 1 until 0 when get to 0 to display msgbox
ZurdoDev 24-Sep-20 14:19pm
   
If you want to countdown in each tick event, create a variable that stores the number 10 and then in the tick event just subtract one from it.
diablo22 24-Sep-20 14:47pm
   
something like:
Dim progress As Integer = My.Settings.isBackUpTime
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Try
progress = progress - 1
'Timer2.Interval = 1

If progress = 0 Then
MsgBox("start copy")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
ZurdoDev 24-Sep-20 14:50pm
   
It is still not clear exactly what you want to have happen, but yes, something like that.
diablo22 24-Sep-20 14:52pm
   
it is clear.
First get the number from my.settings.time
Then timer tick each second reduce progress - 1 until gets 0 then when its 0 show msgbox
ZurdoDev 24-Sep-20 14:55pm
   
Good. I'll post that as a solution.

You have no choice but to learn to use the debugger. It's going to tell you what the values are at any point in your code while it's running.

Set a breakpoint on the If statement, run the code, and then the breakpoint is hit, the code will stop running and show you the line that's going to execute next. Hove the mouse over the Time part of My.Settings.Time and it should show you the current value. If that value is not what you expect, you're going to have to dig into why.
   
As mentioned in the comments, declare a class level variable and then in your timer tick event subtract one from that variable and then do your if statement to check the value.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900