Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

flashing text boxes at different intervals 3

Status
Not open for further replies.

JaredTaylor74

Technical User
Jul 26, 2004
51
US
is there a way to have two seperate flashing text boxes in a form flash at different intervals?

here is what i have in the form timer ...

Me.lblIdleAlert.ForeColor = vbYellow
Me.lblIdleAlert.Visible = Not Me.lblIdleAlert.Visible

that works for the one text box... but i want another text box to flash at a different rate.. one at 500, the other at 250

any ideas?

Thanks
 
Did you get any resolution on your previous question? Most of the folks that volunteer their time to post answers sure appreciate knowing if their time was well spent.

For this situation, you have two options. Set the Form TimerInterval to the smallest flash interval, and as you've already done, set the other intervals as multiples of smallest interval. Then in the Timer Event handler, use either static counters or my preference would the the Mod function, to know which textboxes to flash during that specific event.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Another approach would be to use the SetTimer API, and create a separate timer for each TextBox.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
thanks for the tip cajun. i'll make sure and give appropriate feedback to my posts.

i am a little new to vba, so this may be a simple question, but how do I use counters? or even a mod function?

the settimer API sounds like it would be the best solution..
but i don't know what that is either...
sorry i sound so un-educated.
 
At this point, I think that you're better off learning how the built-in Form Timer works with just one textbox before venturing into the API world. Is what you have working for one textbox? If not, then what is it doing, and it might be helpful to post the entire Form_Timer event code.



Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
here is what i have for the "on timer"
timer interval is set to 1000

Private Sub Form_Timer()
Me.lblIdleAlert.ForeColor = vbYellow
Me.lblIdleAlert.Visible = Not Me.lblIdleAlert.Visible
End Sub

i have another textbox I would like to flash red at half a second rate, on another section of the form.

so one is going twice as fast as the other.

yes, the form works... I just want to tweak it a little.
 
First, as I suggested earlier, you need to change the interval the shortest applicable time frame which is a divisor of the three blink intervals. Lets assume that I have three textboxes and I want them to blink at 500, 750, and 1000. The shortest application time frame would be 250 as that is largest value which is a divisor of the three blink intervals. So the 500 interval will blink every other timer event, the 750 every third timer event, and 1000 every 4th timer event.
Code:
Private Sub Form_Timer()

   Static Counter as Integer

   Counter = Counter + 1
   If ((Counter Mod 4) = 0) Then 
       Me.lblIdle1000Alert.ForeColor = vbYellow
       Me.lblIdle1000Alert.Visible = Not Me.lblIdle1000Alert.Visible
       Me.lblIdle500Alert.ForeColor = vbRed
       Me.lblIdle500Alert.Visible = Not Me.lblIdle500Alert.Visible
   Else
      If ((Counter Mod 3) = 0) Then
         Me.lblIdle750Alert.ForeColor = vbBlue
         Me.lblIdle750Alert.Visible = Not Me.lblIdle750Alert.Visible
      Else
         If ((Counter Mod 2) = 0) Then
            Me.lblIdle500Alert.ForeColor = vbRed
            Me.lblIdle500Alert.Visible = Not Me.lblIdle500Alert.Visible
      End If
   End If

End Sub

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Left out 1 thing. To prevent an overflow error you should add one line, as the very last line in the Event handler.
[tt]
End If

If (Counter = 30000) Then
Counter = 0
End If

End Sub
[/tt]

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
wow.. cool stuff. have no idea why it works, but it does. i understand why i put my timer at the lowest time, but the counters and mods i don't quite grasp. but that's ok, i'll get there.

quick question... how did you get your code in that nice little subwindow thing?

thanks a ton cajun.

Jared
 
Use the TGML tags. There is a checkbox and link at the bottom of this posting which says "Process TGML", and if you click on the link, you'll see all of the available commands including the "code" tag.

Analyzing the code, each time the timer event fire, the counter is incremented by 1. If the value of the counter is evenly divisible by 4 (Counter Mod 4), then your on the 4th, 8th, 12th, etc time in the event handler. With a counter value of 250, that means that you hitting 1000, 2000, 3000 timer intervals, which means you need to toggle the 1000 interval timer AND the 500 interval timer. If it's not divisible by 4, then check if it's divisible by 3. That will correspond to 750, 1500, 2250, etc, which means you need to toggle the 750 interval label.

Of course, as I'm explaining this, I realize that you also need to check First if it's evenly divisible by 12, because at that point all three labels must toggle. You should add that condition as the first condition to check.

Anyway, if the Counter is not divisible by 12, not divisble by 4, and not divisible by 3, you still need to check if it's divisible by 2, because then just the 500 interval lable will need to be toggled.


Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Instead of checking the divisibility by 12 and so forth, simply avoid the Else parts:
Code:
Private Sub Form_Timer()
  Static Counter As Integer
  Counter = Counter + 1
  If (Counter Mod 4) = 0 Then 
    Me.lblIdle1000Alert.ForeColor = vbYellow
    Me.lblIdle1000Alert.Visible = Not Me.lblIdle1000Alert.Visible
  End If
  If (Counter Mod 3) = 0 Then
    Me.lblIdle750Alert.ForeColor = vbBlue
    Me.lblIdle750Alert.Visible = Not Me.lblIdle750Alert.Visible
  End If
  If (Counter Mod 2) = 0 Then
    Me.lblIdle500Alert.ForeColor = vbRed
    Me.lblIdle500Alert.Visible = Not Me.lblIdle500Alert.Visible
  End If
  If Counter = 30000 Then
    Counter = 0
  End If
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top