Results 1 to 8 of 8

Thread: Question on timer class

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Location
    west
    Posts
    96

    Question on timer class

    Hi everybody

    I would like to ask a question on timer class........for example, the user clicks on the button, the timer starts to count for 1 sec and then i wish to hv a msgbox emerge to tell the user "no response" immediately after the 1 sec....... i would be appreciated if anyone can help me.......thank u very much


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRx.Click

    End Sub

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Question on timer class

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRx.Click
    2.     Timer1.Interval = 1000
    3.     Timer1.Enabled = True
    4.     'Do something if they respond ???
    5.     '
    6.     'If they respond in time turn off the timer?
    7.     Timer1.Enabled = False
    8. End Sub
    9.  
    10. Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    11.     MessageBox.Show("Times Up!", "Timer")
    12. End Sub
    Something similar to this.

    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Question on timer class

    add a timer at design time, click on it and in properties set the interval to 1000 (milliseconds= 1 second).

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Timer1.Enabled = True
    3.     End Sub
    4.  
    5.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    6.         MsgBox("boo")
    7.         Timer1.Enabled = False
    8.     End Sub
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Question on timer class

    But if they respond in the time allotted then the timer will still fire.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Question on timer class

    Quote Originally Posted by RobDog888
    But if they respond in the time allotted then the timer will still fire.
    putting code in that commented area in button_click wont do anything unless he has an infinite loop, which is inefficient anyways
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Question on timer class

    True , but I didnt know what other actions the poster had in place while he was waiting for a response.
    Like an event for entering text in a textbox and pressing another button?

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Location
    west
    Posts
    96

    Re: Question on timer class

    hi Everybody

    Thanks for the reply.....i'm have actually written a download process after the Timer1.Enabled = True and i wanted the timer to turn off if the download process complete on time.............but now.....i get this error "Handles clause requires a WithEvents variable"......what does this mean? can any 1 tell me this? thank u very much



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRx.Click
    Timer1.Interval = 1000
    Timer1.Enabled = True

    'Do something if they respond ???
    '
    ' If they respond on time turn off the timer

    Timer1.Enabled = False

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    MessageBox.Show("Time out !!", "Timer")
    End Sub
    End Class

  8. #8
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Question on timer class

    Quote Originally Posted by chioman
    hi Everybody

    Thanks for the reply.....i'm have actually written a download process after the Timer1.Enabled = True and i wanted the timer to turn off if the download process complete on time.............but now.....i get this error "Handles clause requires a WithEvents variable"......what does this mean? can any 1 tell me this? thank u very much



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRx.Click
    Timer1.Interval = 1000
    Timer1.Enabled = True

    'Do something if they respond ???
    '
    ' If they respond on time turn off the timer

    Timer1.Enabled = False

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    MessageBox.Show("Time out !!", "Timer")
    End Sub
    End Class
    that's probably because you copy/pasted the code hehe
    You need to declare a variable first before you can reference an event for it. You can either do it manually, which I dont think would be easy for you..... .or

    umm do this: you probably already have the button so the error should be from the timer. In design view of your form, add a TIMER control to your form and then double click on the timer. VS.NET will automatically generate the code for Timer_Tick event for you. Then you can put your timer code in there.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width