Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

automatically chaging colors

Posted on 2002-07-18
4
Medium Priority
?
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

618 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