?
Solved

automatically chaging colors

Posted on 2002-07-18
4
Medium Priority
?
192 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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
Course of the Month14 days, 2 hours left to enroll

801 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