Solved

automatically chaging colors

Posted on 2002-07-18
4
185 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
Comment Utility
'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
Comment Utility
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
Comment Utility
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
Comment Utility
Comment from expert accepted as answer

Computer101
E-E Admin
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

15 Experts available now in Live!

Get 1:1 Help Now