By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

Colour Cycle in forms?

P: n/a
Hi there,

I have written the following code to colour cycle the background in one of
my forms.

The problem is it only cycles from Black to Red and then reverts back to
Black.

Does anyone have any idea what's causing this?

Thanks in advance,

John

-----------------------------------------------------

Option Compare Database
Option Explicit
Dim BackGrd As Long

Private Sub Form_Load()

BackGrd = 1

End Sub

Private Sub Form_Timer()

BackGrd = BackGrd + 1

[Forms]![Menu].[Detail].BackColor = BackGrd

End Sub
Nov 13 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
It actually works as advertised. The Timer event only fires once, after the
specified delay. Not sure why you'd want to constantly change colors, but
try an event like OnCurrent that stays active and create your own time
intervals.
-Ed

"John Ortt" <Jo******@Idontwantspamsonoreturnaddress.com> wrote in message
news:42********@glkas0286.greenlnk.net...
Hi there,

I have written the following code to colour cycle the background in one of
my forms.

The problem is it only cycles from Black to Red and then reverts back to
Black.

Does anyone have any idea what's causing this?

Thanks in advance,

John

-----------------------------------------------------

Option Compare Database
Option Explicit
Dim BackGrd As Long

Private Sub Form_Load()

BackGrd = 1

End Sub

Private Sub Form_Timer()

BackGrd = BackGrd + 1

[Forms]![Menu].[Detail].BackColor = BackGrd

End Sub

Nov 13 '05 #2

P: n/a
It doesn't only fire once Ed,

I can see the form gradually changing from black (0) to Red (255) but after
Red it reverts back to 0 with no graduation.

This means it's working the first 255 times after which it reverts to 0 and
works another 255 times and so on.

My immediate thought was that I had used the wrong type of number format
(-255 to 255 or similar) but this is not the case for 'Long' Integers.

I also have my timer interval set to 100 on the form but I don't see how
that can afect the resul (other than making the graduation slower).

I just can't figure it.

As to the reason why I want to do it it's purely as a lesson in VB and
Access for me....

Thanks for taking a stab anyway Ed, and if I have misunderstood your post
please feel free to correct me.

"Ed Robichaud" <ed*********@wdn.com> wrote in message
news:zQ*****************@monger.newsread.com...
It actually works as advertised. The Timer event only fires once, after the specified delay. Not sure why you'd want to constantly change colors, but
try an event like OnCurrent that stays active and create your own time
intervals.
-Ed

"John Ortt" <Jo******@Idontwantspamsonoreturnaddress.com> wrote in message
news:42********@glkas0286.greenlnk.net...
Hi there,

I have written the following code to colour cycle the background in one of my forms.

The problem is it only cycles from Black to Red and then reverts back to
Black.

Does anyone have any idea what's causing this?

Thanks in advance,

John

-----------------------------------------------------

Option Compare Database
Option Explicit
Dim BackGrd As Long

Private Sub Form_Load()

BackGrd = 1

End Sub

Private Sub Form_Timer()

BackGrd = BackGrd + 1

[Forms]![Menu].[Detail].BackColor = BackGrd

End Sub


Nov 13 '05 #3

P: n/a
On Mon, 13 Jun 2005 11:12:32 +0100, "John Ortt"
<Jo******@Idontwantspamsonoreturnaddress.com> wrote:

Set your timer to 10 msec and let it rip for a few minutes. You'll see
other colors appear. Don't expect a gradual transition. Look at each
individual RGB color that's generated, and you'll understand why you
won't have a perfect rainbow effect.

-Tom.
Dim BackGrd As Long

Private Sub Form_Load()

BackGrd = 1

End Sub

Private Sub Form_Timer()

BackGrd = BackGrd + 1

[Forms]![Menu].[Detail].BackColor = BackGrd

End Sub


Nov 13 '05 #4

P: n/a
I think I've figured it out.

It isn't repeating the same red to black cycle, it's going through each red
to black cycle. If I left it running long enough it would eventually get to
the other colours.

Now to figure out how to get the result I want :)
"John Ortt" <Jo******@Idontwantspamsonoreturnaddress.com> wrote in message
news:42**********@glkas0286.greenlnk.net...
It doesn't only fire once Ed,

I can see the form gradually changing from black (0) to Red (255) but after Red it reverts back to 0 with no graduation.

This means it's working the first 255 times after which it reverts to 0 and works another 255 times and so on.

My immediate thought was that I had used the wrong type of number format
(-255 to 255 or similar) but this is not the case for 'Long' Integers.

I also have my timer interval set to 100 on the form but I don't see how
that can afect the resul (other than making the graduation slower).

I just can't figure it.

As to the reason why I want to do it it's purely as a lesson in VB and
Access for me....

Thanks for taking a stab anyway Ed, and if I have misunderstood your post
please feel free to correct me.

"Ed Robichaud" <ed*********@wdn.com> wrote in message
news:zQ*****************@monger.newsread.com...
It actually works as advertised. The Timer event only fires once, after the
specified delay. Not sure why you'd want to constantly change colors, but
try an event like OnCurrent that stays active and create your own time
intervals.
-Ed

"John Ortt" <Jo******@Idontwantspamsonoreturnaddress.com> wrote in message news:42********@glkas0286.greenlnk.net...
Hi there,

I have written the following code to colour cycle the background in one of my forms.

The problem is it only cycles from Black to Red and then reverts back

to Black.

Does anyone have any idea what's causing this?

Thanks in advance,

John

-----------------------------------------------------

Option Compare Database
Option Explicit
Dim BackGrd As Long

Private Sub Form_Load()

BackGrd = 1

End Sub

Private Sub Form_Timer()

BackGrd = BackGrd + 1

[Forms]![Menu].[Detail].BackColor = BackGrd

End Sub



Nov 13 '05 #5

P: n/a
Thanks for the reply Tom,

I was just prob just getting my head round it as you were writing your reply
:)
"Tom van Stiphout" <no*************@cox.net> wrote in message
news:26********************************@4ax.com...
On Mon, 13 Jun 2005 11:12:32 +0100, "John Ortt"
<Jo******@Idontwantspamsonoreturnaddress.com> wrote:

Set your timer to 10 msec and let it rip for a few minutes. You'll see
other colors appear. Don't expect a gradual transition. Look at each
individual RGB color that's generated, and you'll understand why you
won't have a perfect rainbow effect.

-Tom.


Nov 13 '05 #6

P: n/a

"John Ortt" <Jo******@Idontwantspamsonoreturnaddress.com> schreef in bericht news:42**********@glkas0286.greenlnk.net...
It doesn't only fire once Ed,

I can see the form gradually changing from black (0) to Red (255) but after
Red it reverts back to 0 with no graduation.

This means it's working the first 255 times after which it reverts to 0 and
works another 255 times and so on.

My immediate thought was that I had used the wrong type of number format
(-255 to 255 or similar) but this is not the case for 'Long' Integers.

I also have my timer interval set to 100 on the form but I don't see how
that can afect the resul (other than making the graduation slower).


The Timer-event keeps on firing until the TimerInterval is set to zero indeed.

Try something like:
Private Sub Form_Load()
BackGrd = 100000
End Sub

In your Timer-event:
BackGrd = BackGrd + 1000
Me.Repaint (Maybe this shows the results better)

So increase the steps to reach higher values.
I am thinking it just takes too long to 'reach' a color like yellow (8454143)

Arno R

Nov 13 '05 #7

P: n/a
You're correct, of course. The On Timer event fires at each defined
interval. Yours set at 100 will fire every 0.1 seconds.

I meant to say that the On Load event only fires once. If you slow the
interval and/or increase the color increment, you'll notice that your code
actually produces no gradations, just one color change, then a reversion.
Like you, I don't understand what would stop that process from continuing to
white (16777215), and what would cause it to reverse -decrement the BackGrd
value. I'll play with this later today when time permits.

-Ed
"John Ortt" <Jo******@Idontwantspamsonoreturnaddress.com> wrote in message
news:42**********@glkas0286.greenlnk.net...
It doesn't only fire once Ed,

I can see the form gradually changing from black (0) to Red (255) but
after
Red it reverts back to 0 with no graduation.

This means it's working the first 255 times after which it reverts to 0
and
works another 255 times and so on.

My immediate thought was that I had used the wrong type of number format
(-255 to 255 or similar) but this is not the case for 'Long' Integers.

I also have my timer interval set to 100 on the form but I don't see how
that can afect the resul (other than making the graduation slower).

I just can't figure it.

As to the reason why I want to do it it's purely as a lesson in VB and
Access for me....

Thanks for taking a stab anyway Ed, and if I have misunderstood your post
please feel free to correct me.

"Ed Robichaud" <ed*********@wdn.com> wrote in message
news:zQ*****************@monger.newsread.com...
It actually works as advertised. The Timer event only fires once, after

the
specified delay. Not sure why you'd want to constantly change colors,
but
try an event like OnCurrent that stays active and create your own time
intervals.
-Ed

"John Ortt" <Jo******@Idontwantspamsonoreturnaddress.com> wrote in
message
news:42********@glkas0286.greenlnk.net...
> Hi there,
>
> I have written the following code to colour cycle the background in one of > my forms.
>
> The problem is it only cycles from Black to Red and then reverts back
> to
> Black.
>
> Does anyone have any idea what's causing this?
>
> Thanks in advance,
>
> John
>
> -----------------------------------------------------
>
> Option Compare Database
> Option Explicit
> Dim BackGrd As Long
>
> Private Sub Form_Load()
>
> BackGrd = 1
>
> End Sub
>
> Private Sub Form_Timer()
>
> BackGrd = BackGrd + 1
>
> [Forms]![Menu].[Detail].BackColor = BackGrd
>
> End Sub
>
>



Nov 13 '05 #8

P: n/a
There are some algorithms on line if you want to convert
them to your purposes. Just Google "RGB Rainbow VBA" and
look through some of the real Rainbow shifting routines.

If you want something that still looks pretty gradual, but
is not the rainbow progression...

Option Compare Database
Option Explicit
Private miRed As Integer
Private miBlue As Integer
Private miGreen As Integer
Private mbFlipRed As Integer
Private mbFlipBlue As Integer
Private mbFlipGreen As Integer

Private Sub Form_Load()
Me.Detail.BackColor = 0
' I should have initialized everything! oh, well.
End Sub

Private Sub Form_Timer()
' Cycle through each of the RGB color values,
' each with a different periodicity. To keep
' from seeing jarring shifts, alternate directions.
' Also, the step values are prime and small in order
' to keep the total cycle long.

miRed = miRed + mbFlipRed * 2
If miRed <= 0 Then
mbFlipRed = 1
miRed = 0
End If
If miRed > 255 Then
mbFlipRed = -1
miRed = 255
End If

miGreen = miGreen + mbFlipGreen * 3
If miGreen <= 0 Then
mbFlipGreen = 1
miGreen = 0
End If
If miGreen > 255 Then
mbFlipGreen = -1
miGreen = 255
End If

miBlue = miBlue + mbFlipBlue * 5
If miBlue <= 0 Then
mbFlipBlue = 1
miBlue = 0
End If
If miBlue > 255 Then
mbFlipBlue = -1
miBlue = 255
End If

Me.Detail.BackColor = RGB(miRed, miGreen, miBlue)

End Sub

If this works for you, it's cheap, quick, and simple.

Kevin
John Ortt<Jo******@Idontwantspamsonoreturnaddress.com>
6/13/2005 8:37 AM >>>Thanks for the reply Tom,

I was just prob just getting my head round it as you were
writing your reply
:)
"Tom van Stiphout" <no*************@cox.net> wrote in
message
news:26********************************@4ax.com.. .
On Mon, 13 Jun 2005 11:12:32 +0100, "John Ortt"
<Jo******@Idontwantspamsonoreturnaddress.com> wrote:

Set your timer to 10 msec and let it rip for a few

minutes. You'll see
other colors appear. Don't expect a gradual transition.

Look at each
individual RGB color that's generated, and you'll

understand why you
won't have a perfect rainbow effect.

-Tom.

Nov 13 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.