timer problem

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 757 Views - Last Post: 12 October 2012 - 08:18 PM Rate Topic: -----

#1 ZHodges8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 12-October 12

timer problem

Posted 12 October 2012 - 02:30 PM

Hello i'm fairly new to programming and i'm having a problem with a click counter. see , i want to make it so it counts down from ten and when it hits zero and it won't let you click anymore. Any help would be greatly appreciated!
Is This A Good Question/Topic? 0
  • +

Replies To: timer problem

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: timer problem

Posted 12 October 2012 - 02:38 PM

Did you try to code something. If you did, post the code. If you didn't yet, than try to do something like this:
  • declare variable of appropriate type, and assign it the value of 10. Make sure the scope of it allows it to be accessed from button click event handling routine
  • put the Button on the form
  • in button click event handling routine, decrement the value of counter variable
  • check if it's value is now equal to zero
  • if it is, set button's Enabled or Visible property to false

Was This Post Helpful? 1
  • +
  • -

#3 ZHodges8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 12-October 12

Re: timer problem

Posted 12 October 2012 - 02:42 PM

I declared "t" as a variable on the form. Here's part of the code. But there is'nt much else that i could think of for the timer code.


[ Private Sub tmrtime_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrtime.Tick
t += 1
Me.lblt.Text = t
If lblt < 10 Then]
Was This Post Helpful? 0
  • +
  • -

#4 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: timer problem

Posted 12 October 2012 - 02:51 PM

So you literally meant timer. I thought you wanted to say counter. OK. Timer has Interval property, where you declare time between ticks in milliseconds. If you meant by counting down from 10 seconds, you can just set interval to 1000, and then display countdown in timer tick handling routine (as you started). It would be easier, if you'd subtract t starting from 10 and check if it is 0 after subtraction. By not letting user clicking... what do you mean by that? Not letting him/her click the form, click the buttons,...?
Was This Post Helpful? 0
  • +
  • -

#5 ZHodges8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 12-October 12

Re: timer problem

Posted 12 October 2012 - 02:56 PM

i mean after the timer hits 0 , i want it so the number on my label will not go up anymore if the user clicks the button after.
Was This Post Helpful? 0
  • +
  • -

#6 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: timer problem

Posted 12 October 2012 - 03:05 PM

Take some time, and try to do some coding. You need to decide are you decrementing/incrementing t variable on timer tick, or on button click, or on both events. In other words: would you want to allow user click 10 times on button, display number of button clicks in label, and than prevent incrementing the value of click count if it reaches 10. Would you like to just stop counting, or disable button? Or are you giving the user 10 seconds only, and then disabling whole form? From your answers, I can't tell what your goal is.
Was This Post Helpful? 0
  • +
  • -

#7 ZHodges8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 12-October 12

Re: timer problem

Posted 12 October 2012 - 03:10 PM

My goal is to make it so after the 10 seconds are up on the timer, the button is disabled from adding more to the label. (The label is where the number of clicks come up)
Was This Post Helpful? 0
  • +
  • -

#8 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: timer problem

Posted 12 October 2012 - 03:26 PM

Then set timer interval to 10000. You can do it in design, or by code: Timer1.Interval = 10000. It would be wise to do it in form load event handling routine. Then you need to start that timer, with it's .Start() method. This too should happen when form loads.

In timer tick handling method, you set button's Enabled property to false, and stop the timer by calling it's .Stop() method.

In button click event handling routine, you just simply increment value of t variable by one, and assign it to .Text property of label.
Was This Post Helpful? 0
  • +
  • -

#9 ZHodges8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 12-October 12

Re: timer problem

Posted 12 October 2012 - 03:39 PM

So far this is the coding for the timer. But by putting "t = 10- 1" that is only giving me "9" in the label and will not countdown further.


[Private Sub tmrtime_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrtime.Tick
t = 10 - 1
Me.lblt.Text = t
tmrtime.Interval = 10000
tmrtime.stop()] (also have tmrtime.start() in my button1 click event)
Was This Post Helpful? 0
  • +
  • -

#10 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1055
  • View blog
  • Posts: 4,083
  • Joined: 02-July 08

Re: timer problem

Posted 12 October 2012 - 03:49 PM

You are telling it to be 10 - 1 which = 9 so it won't go down. Do you mean to be using:
t -= 1?
Was This Post Helpful? 1
  • +
  • -

#11 ZHodges8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 12-October 12

Re: timer problem

Posted 12 October 2012 - 04:36 PM

That worked but now how would i make it countdown? i declared "a" as a variable and set it as "dim a as integer = 10" but it still will not work here's the code now.


[Private Sub tmrtime_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrtime.Tick
t -= 1
Me.lblt.Text = t - a
tmrtime.Interval = 10000
tmrtime.Stop()

End Sub]
Was This Post Helpful? 0
  • +
  • -

#12 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1055
  • View blog
  • Posts: 4,083
  • Joined: 02-July 08

Re: timer problem

Posted 12 October 2012 - 04:45 PM

Your not decrementing the same variable. You don't need the a variable just display the t variable in the label. If you call .Stop on the timer in the tick event it turns it off the very first time the tick event is called - hence the reason it is not continuing down.
Was This Post Helpful? 0
  • +
  • -

#13 ZHodges8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 12-October 12

Re: timer problem

Posted 12 October 2012 - 05:01 PM

So where would i put the .stop() command?
Was This Post Helpful? 0
  • +
  • -

#14 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: timer problem

Posted 12 October 2012 - 05:02 PM

You're also going to want to change that interval so that every second you get an updated number. Right now you won't see anything happen for 10 seconds. I believe you want it to countdown the seconds so 1000ms is close to 1 second.
Was This Post Helpful? 0
  • +
  • -

#15 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1055
  • View blog
  • Posts: 4,083
  • Joined: 02-July 08

Re: timer problem

Posted 12 October 2012 - 05:03 PM

Depends on when you want to stop it? You could have it in the tick event if you protect it with a boolean check.

If t = 0 Then timer.Stop()

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2