12 Replies - 5830 Views - Last Post: 18 February 2010 - 10:23 AM Rate Topic: -----

#1 Mary4321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 18-February 10

countdown timer

Posted 18 February 2010 - 06:11 AM

Hello everyone, I am looking for some help regarding the vb.net timer. The program I would like to crete is pretty straight forward. But I am still finding problems.

The application simply has one button on it, when that button is selected a timer in the back ground will be triggered (for example 30 mins). After the timer is up I would like it to display a message.

Thank you in advance for your help.

Mary
Is This A Good Question/Topic? 0
  • +

Replies To: countdown timer

#2 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: countdown timer

Posted 18 February 2010 - 06:20 AM

Okay well first I recommend you read the forum rules

[rules][/rules]

Secondly I recommend that you do a quick search.

I will give you no code but I will walk you through what you have to do...

  • Firstly you need a timer that is set to a ceartin time to tick on
  • then everytime it ticks it needs to subtract that value from
  • a publicly declared integer
  • when that integer reaches 0 it...
  • tells you that it has reached 0

Was This Post Helpful? 0
  • +
  • -

#3 Mary4321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 18-February 10

Re: countdown timer

Posted 18 February 2010 - 07:30 AM

Hello again, thank you for the quick reply. Below is my code. The errors I am getting is as follows:

'Start' is not a member of 'System.Windows.Forms.Timer'.




Public Class HomePage
Dim sec As Integer

Private Sub Form1_Load()
Timer.Start()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Startbut.Click
MsgBox("zero")
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
lblClock.Text = TimeOfDay
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub

Private Sub Message_ParentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Message.ParentChanged

End Sub

Private Sub lblClock_ParentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblClock.ParentChanged

End Sub

Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Startbut.Text = Startbut.Text - 1
If Startbut.Text = 0 Then
Timer1.Stop()
Startbut.Text = "you have been out for 1 hour"
Startbut.Enabled = True
End If
End Sub
End Class
Was This Post Helpful? 0
  • +
  • -

#4 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: countdown timer

Posted 18 February 2010 - 07:56 AM

Hi,

I think you should name it:

Private Sub Form1_Load()
Timer1.Start()
' ore you set it also as [b]Timer1.Enabled=true[/b]
End Sub



This post has been edited by Luc001: 18 February 2010 - 08:24 AM

Was This Post Helpful? 0
  • +
  • -

#5 xnn  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 227
  • Joined: 10-February 10

Re: countdown timer

Posted 18 February 2010 - 08:01 AM

you have

timer.start()



Since start is not a shared member of the Timer class you should reference your object

timer1.start()



Also it is good practice to have Option Explicit and Strict ON and Option Infer OFF. I'm at work and can't explain what they do. It's worth a google though.
Was This Post Helpful? 0
  • +
  • -

#6 Guest_mary4321*


Reputation:

Re: countdown timer

Posted 18 February 2010 - 08:20 AM

hello, thank you for the feedback, I have chnaged this to timer1.start and still have the same problem :(

Mary
Was This Post Helpful? 0

#7 xnn  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 227
  • Joined: 10-February 10

Re: countdown timer

Posted 18 February 2010 - 08:32 AM

You have changed all Timer.Start() to Timer1.Start()? (It helps if you rename all your controls to something more descriptive) You still get the error Start() is not a member of system.windows.forms.timer?
Was This Post Helpful? 0
  • +
  • -

#8 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: countdown timer

Posted 18 February 2010 - 09:03 AM

Hi,

After a closer look at your code found that they're several problems.
Here's an explanation:

Public Class Form1
    Dim sec As Integer
    Dim timer As New System.Windows.Forms.Timer ' declare your timer like this

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click
        MsgBox("zero")
    End Sub

    Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        lblClock.Text = TimeOfDay
        stbutt.Text = stbutt.Text - 1
        If stbutt.Text = 0 Then
            timer.Stop()
            stbutt.Text = "you have been out for 1 hour"
' it doesn't need to enable a button to do something 
'   you need a performclick for that

            stbutt.PerformClick()         
End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   ' you need also that the timer gets activated
   ' Addhandler and adressof
        AddHandler timer.Tick, AddressOf timer_Tick         
        timer.Enabled = True  ' to start your timer
        timer.Interval = 1000   ' to set the interval       
        stbutt.Text = "60"
        lblClock.Text = TimeOfDay

    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click
        MsgBox("zero")
    End Sub
End Class


It should work now.

This post has been edited by Luc001: 18 February 2010 - 09:04 AM

Was This Post Helpful? 0
  • +
  • -

#9 xnn  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 227
  • Joined: 10-February 10

Re: countdown timer

Posted 18 February 2010 - 09:18 AM

You could avoid instantiating the timer object and using the delagate code if you drag and drop the timer control from the Visual Studio Toolbox.
Was This Post Helpful? 0
  • +
  • -

#10 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: countdown timer

Posted 18 February 2010 - 09:25 AM

Hi xnn,

That's true and the more easy way, but the goal was do work with the system.windows.Forms Timer.
Was This Post Helpful? 0
  • +
  • -

#11 xnn  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 227
  • Joined: 10-February 10

Re: countdown timer

Posted 18 February 2010 - 09:31 AM

I could be wrong, I do most my vb.net coding with my companies proprietary controls, but I believe the timer control dragged on to the windows form instantiates a System.Windows.Forms.Timer object in the designer code.
Was This Post Helpful? 0
  • +
  • -

#12 Guest_mary4321*


Reputation:

Re: countdown timer

Posted 18 February 2010 - 09:36 AM

View PostLuc001, on 18 February 2010 - 08:03 AM, said:

Hi,

After a closer look at your code found that they're several problems.
Here's an explanation:

Public Class Form1
    Dim sec As Integer
    Dim timer As New System.Windows.Forms.Timer ' declare your timer like this

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click
        MsgBox("zero")
    End Sub

    Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        lblClock.Text = TimeOfDay
        stbutt.Text = stbutt.Text - 1
        If stbutt.Text = 0 Then
            timer.Stop()
            stbutt.Text = "you have been out for 1 hour"
' it doesn't need to enable a button to do something 
'   you need a performclick for that

            stbutt.PerformClick()         
End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   ' you need also that the timer gets activated
   ' Addhandler and adressof
        AddHandler timer.Tick, AddressOf timer_Tick         
        timer.Enabled = True  ' to start your timer
        timer.Interval = 1000   ' to set the interval       
        stbutt.Text = "60"
        lblClock.Text = TimeOfDay

    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click
        MsgBox("zero")
    End Sub
End Class


It should work now.





Hi there, thanks a million for havin a look at my code. I am now getting an error message saying that "performclick" is not a member.

Mary
Was This Post Helpful? 0

#13 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: countdown timer

Posted 18 February 2010 - 10:23 AM

View Postmary4321, on 18 February 2010 - 08:36 AM, said:

View PostLuc001, on 18 February 2010 - 08:03 AM, said:

Hi,

After a closer look at your code found that they're several problems.
Here's an explanation:

Public Class Form1
    Dim sec As Integer
    Dim timer As New System.Windows.Forms.Timer ' declare your timer like this

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click
        MsgBox("zero")
    End Sub

    Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        lblClock.Text = TimeOfDay
        stbutt.Text = stbutt.Text - 1
        If stbutt.Text = 0 Then
            timer.Stop()
            stbutt.Text = "you have been out for 1 hour"
' it doesn't need to enable a button to do something 
'   you need a performclick for that

            stbutt.PerformClick()         
End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   ' you need also that the timer gets activated
   ' Addhandler and adressof
        AddHandler timer.Tick, AddressOf timer_Tick         
        timer.Enabled = True  ' to start your timer
        timer.Interval = 1000   ' to set the interval       
        stbutt.Text = "60"
        lblClock.Text = TimeOfDay

    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stbutt.Click
        MsgBox("zero")
    End Sub
End Class


It should work now.





Hi there, thanks a million for havin a look at my code. I am now getting an error message saying that "performclick" is not a member.

Mary


Hi Mary,

I tested my code before posting and everything worked.
What did you do?

This post has been edited by Luc001: 18 February 2010 - 10:30 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1