Solved

automatically chaging colors

Posted on 2002-07-18
4
188 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

809 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