[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

Would like to update "text1.text = Time" (in its own sub) without having to call on its sub

I have a "Sub NewTime" dedicated JUST to update the time every 30 seconds or so. I call on it from other subs. the problem is sometimes other subs get wrapped up in their loops and 'NewTime' doesn't get called on until minutes later. Is there a way that I could have 'NewTime' run independently of the other subs, updating itself without needing to be called by other subs?
0
JohnDoeSr
Asked:
JohnDoeSr
2 Solutions
 
ShauliCommented:
Why not call NewTime from a timer every 30 seconds?

S
0
 
jkaiosCommented:
I agree with Shauli and to clarify what he is actually referring to that you have to place a Timer control on your form and in the Timer() event
you code it as follows:

1. Set the "Interval" property of the Timer control to 1000 (which means that the timer fires every 1 second)
2. Code your timer as follows:

Private Sub Timer1()

  Static iSecond As Integer

  If iSecond >= 30 Then      
     Text1.Text = Time          'Update the time text box
     iSecond = 0                    'Reset counter to start again from 1
  Else
     iSecond = iSecond + 1    'Increment the seconds counter
  End If

End Sub
0
 
ShauliCommented:
jkaios , why not set the interval to 30,000 and then do:

Private Sub Timer1()
Timer1.Enabled = False
Call NewTime
Timer1.Enabled = True
End Sub

S
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jkaiosCommented:
That's a good one Shauli, again I agree with you 100%... all credits should be on you

Cheers
jk
0
 
JR2003Commented:
You could add DoEvents commands into the loops that are getting tied up.
This would allow the Timer event to be triggered and run during the looping.
0
 
JohnDoeSrAuthor Commented:
Worked great! I upped thepoints and am splitting them between jkaios for explaining things to me in laymans terms and Shauli for coming up with the idea.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now