473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Help with System.Timers.Timer in a module

Hi,

I'm getting into VB.net with the help of a few books, but have got a
problem grasping how to implement a system.timers.timer

Only 1 of my 3 books mentions timers and that's a Windows.Form.Timer

Basically I need to have a 30 second delay in some module code.

To help me get the hang of it - (that should really be start to get
the hang of it !!) could someone help me with some code that does the
following
Thanks

splowe.

Module Module1

Sub Main ()

MessageBox.Show("OK To start the Delay")

pause for 30 secs

MessageBox.Show("30 second delay has finished")

End Sub
End Module


- Steve Lowe
- E-Mail : NO************@usa.net
- Before Replying Remove .NO.SPAM
- UK Resident although my e-mail address is usa.net
Sep 20 '06 #1
3 8599
Make sure you set your timer interval to be a 1000 ( 1 second )
Make a variable to hold your "30" value.

And before you message box out, if you do not enable=false the timer, the
timer keeps counting.
Thats why its disabled and then enabled again after the fact.

Miro

Public TimerVal As Integer = 0
Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
TimerVal += 1
If TimerVal = 1 Then
Timer1.Enabled = False

MsgBox("started")
Timer1.Enabled = True
ElseIf TimerVal = 30 Then
Timer1.Enabled = False

MsgBox("ended")
Timer1.Enabled = True
TimerVal = 0
End If
End Sub
"Steve Lowe" <sp****@usa.netwrote in message
news:qh********************************@4ax.com...
Hi,

I'm getting into VB.net with the help of a few books, but have got a
problem grasping how to implement a system.timers.timer

Only 1 of my 3 books mentions timers and that's a Windows.Form.Timer

Basically I need to have a 30 second delay in some module code.

To help me get the hang of it - (that should really be start to get
the hang of it !!) could someone help me with some code that does the
following
Thanks

splowe.

Module Module1

Sub Main ()

MessageBox.Show("OK To start the Delay")

pause for 30 secs

MessageBox.Show("30 second delay has finished")

End Sub
End Module


- Steve Lowe
- E-Mail : NO************@usa.net
- Before Replying Remove .NO.SPAM
- UK Resident although my e-mail address is usa.net

Sep 20 '06 #2
Actually you can put a sleep...

So instead of using a timer, and calling your Sub,
if you put something like this

Msgbox( "start" )

System.Threading.Thread.Sleep(30000) ' 30 seconds 1000 for every second.

MSBBox("END")

Your code will wait 30 seconds before it will continue.
So this might be the "Delay" you are looking for. Not a Timer.
"Steve Lowe" <sp****@usa.netwrote in message
news:qh********************************@4ax.com...
Hi,

I'm getting into VB.net with the help of a few books, but have got a
problem grasping how to implement a system.timers.timer

Only 1 of my 3 books mentions timers and that's a Windows.Form.Timer

Basically I need to have a 30 second delay in some module code.

To help me get the hang of it - (that should really be start to get
the hang of it !!) could someone help me with some code that does the
following
Thanks

splowe.

Module Module1

Sub Main ()

MessageBox.Show("OK To start the Delay")

pause for 30 secs

MessageBox.Show("30 second delay has finished")

End Sub
End Module


- Steve Lowe
- E-Mail : NO************@usa.net
- Before Replying Remove .NO.SPAM
- UK Resident although my e-mail address is usa.net

Sep 20 '06 #3
Hi

Thanks for that -

I'm getting a Handles clause requires a WithEvents Variable error in
this line

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed

^^^^^
and also a Timer1 is not declared error at all references to
Timer1.Enabled
Regards

Steve.
On Wed, 20 Sep 2006 09:42:02 -0400 "Miro" <mi******@golden.netwrote:
>Make sure you set your timer interval to be a 1000 ( 1 second )
Make a variable to hold your "30" value.

And before you message box out, if you do not enable=false the timer, the
timer keeps counting.
Thats why its disabled and then enabled again after the fact.

Miro

Public TimerVal As Integer = 0
Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
TimerVal += 1
If TimerVal = 1 Then
Timer1.Enabled = False

MsgBox("started")
Timer1.Enabled = True
ElseIf TimerVal = 30 Then
Timer1.Enabled = False

MsgBox("ended")
Timer1.Enabled = True
TimerVal = 0
End If
End Sub
"Steve Lowe" <sp****@usa.netwrote in message
news:qh********************************@4ax.com.. .
>Hi,

I'm getting into VB.net with the help of a few books, but have got a
problem grasping how to implement a system.timers.timer

Only 1 of my 3 books mentions timers and that's a Windows.Form.Timer

Basically I need to have a 30 second delay in some module code.

To help me get the hang of it - (that should really be start to get
the hang of it !!) could someone help me with some code that does the
following
Thanks

splowe.

Module Module1

Sub Main ()

MessageBox.Show("OK To start the Delay")

pause for 30 secs

MessageBox.Show("30 second delay has finished")

End Sub
End Module


- Steve Lowe
- E-Mail : NO************@usa.net
- Before Replying Remove .NO.SPAM
- UK Resident although my e-mail address is usa.net
- Steve Lowe
- E-Mail : NO************@usa.net
- Before Replying Remove .NO.SPAM
- UK Resident although my e-mail address is usa.net
Sep 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dmitry Demchuk | last post by:
Hi everybody. Recently I ran into situation with System.Threading.Timer in my ASP.NET application. I reinstalled Windows on one of my servers and got timers stop firing events after while, they...
3
by: RitaG | last post by:
Hi. I Have a VB.Net Windows Application that starts up using Sub Main. It's a program that runs in the background and checks something every minute. I use a Timer to accomplish this and it's...
3
by: Peter Johnsson | last post by:
How come the eventhandler for the timer's elapsed time event is called over and over again, even though the AutoReset property is set to false, if you assign a new value to the timer objects...
9
by: Mark Rae | last post by:
Hi, I've seen several articles about using System Timers in ASP.NET solutions, specifically setting them up in Global.asax' Application_OnStart event. I'm thinking about the scenario where I...
10
by: WhiteSocksGuy | last post by:
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have...
5
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated...
4
by: Liverpool fan | last post by:
I have a windows application written using VB .NET that encompasses a countdown timer modal dialog. The timer is a System.Timers.Timer with an interval of 1 second. AutoReset is not set so accepts...
8
by: Ollie Riches | last post by:
I'm looking into a production issue related to a windows service and System.Timers.Timer. The background is the windows service uses a System.Timers.Timer to periodically poll a directory location...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.