|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help with System.Timers.Timer in a moduleI'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.SPAM.splowe@usa.net - Before Replying Remove .NO.SPAM - UK Resident although my e-mail address is usa.net 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 Show quoteHide quote "Steve Lowe" <spl***@usa.net> wrote in message news:qhb2h2lte52n3unr47i4hu314if42espbs@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.SPAM.splowe@usa.net > - Before Replying Remove .NO.SPAM > - UK Resident although my e-mail address is usa.net 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. Show quoteHide quote On Wed, 20 Sep 2006 09:42:02 -0400 "Miro" <miron***@golden.net> wrote: - Steve Lowe>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" <spl***@usa.net> wrote in message >news:qhb2h2lte52n3unr47i4hu314if42espbs@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.SPAM.splowe@usa.net >> - Before Replying Remove .NO.SPAM >> - UK Resident although my e-mail address is usa.net > - E-Mail : NO.SPAM.splowe@usa.net - Before Replying Remove .NO.SPAM - UK Resident although my e-mail address is usa.net 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. Show quoteHide quote "Steve Lowe" <spl***@usa.net> wrote in message news:qhb2h2lte52n3unr47i4hu314if42espbs@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.SPAM.splowe@usa.net > - Before Replying Remove .NO.SPAM > - UK Resident although my e-mail address is usa.net
2005 too smart for it's own good?
BackgroundWorker thread locking UI Detect mouse movement from minimized application Build a Program Now! VB2005 Edit a row read file without locking it. Reading text files date/time in different formats text file problem "File is being used by another process" - error |
|||||||||||||||||||||||