Solved

automatically chaging colors

Posted on 2002-07-18
4
187 Views
Last Modified: 2010-05-03
   
   hi experts
  i want to automatically change the backcolor of a text box from red to green to blue and again red and i want to  repeat this cycle again and again.
   please give me a simple code which i can use in a timer
event or any other control to do this job.
  please make it simple
  thanks
0
Comment
Question by:HIKER
4 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 7161593
'i assume that you have a timer control names timColorChange on the form,
'and the text box is names txtColored

dim arrColors(1 to 3) as long
dim arrPointer as long

Private sub Form_Load()
  arrColors(1) = vbGreen
  arrColors(2) = vbBlue
  arrColors(3) = vbRed
  arrPointer = 1

  timColorChange.Enabled = false
  timColorChange.Interval = 1000
  timColorChange.Enabled = true
End Sub

Private Sub timColorChange_Timer()
  txtColored.BackColor = arrColors(arrPointer)
  arrPointer = arrPointer+1
  if arrPointer>ubound(arrColors) then
    arrPointer = lbound(arrColors)
  end if
End Sub

CHeers
0
 
LVL 4

Expert Comment

by:mcoop
ID: 7161603
put a text box and a timer on a form...

paste away...

  Dim clrIndex As Integer
  Dim bgColr(3) As Long

Private Sub Form_Load()
  ' setup array of allowed colours
  bgColr(0) = vbRed
  bgColr(1) = vbGreen
  bgColr(2) = vbBlue
 
  Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
  ' increment and loop
  clrIndex = (clrIndex + 1) Mod 3
  ' assign backcolor to text box
  Text1.BackColor = bgColr(clrIndex)
End Sub
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8013923
Hi HIKER,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept angelIII's comment(s) as an answer.

HIKER, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 8095649
Comment from expert accepted as answer

Computer101
E-E Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now