473,499 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Colour Cycle in forms?

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
8 1972
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
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
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
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
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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
14667
by: NeoPhreak | last post by:
I am creating a menu for my site and I would like it so that when the onMouseOut even is triggered it will cause the cell of the table to fade out back to the normal color with a delay. Can...
6
2783
by: Lapchien | last post by:
One of my users has asked that a form change it's colour if a particular yes/no box is ticked - possibly made a bit more tricky because the form is tabular..? Thanks, Lap
1
1745
by: Wayne | last post by:
I'm interested to know if I am the only person in the world who hates the default Windows XP colour scheme ie. Blue. Whoever was in charge of this in the Windows design team must have been either...
4
4886
by: Steven | last post by:
Can anyone direct me to a colour picker of the same (or similar quality) to the default .NET one but one that encompasses ability to specify colour by HEX value?
4
1431
by: Thief_ | last post by:
I'm trying to create many squares on a form and for every new square, change the background colour to the next colour. I'm trying to create a colour palette showing all available colours and their...
5
1989
by: kaisersose1995 | last post by:
Hi, I am trying to add some visual confirmation to a continous form, to let the user know if a stored date on the form has passed. I have managed to set the background colour using a simple IF...
21
10587
by: MLH | last post by:
Am having trouble with the following snippet. It stops after only cycling thru open forms. There are many more than that. How to modify this to cycle thru all forms? Sub AllOpenForms() Dim...
0
1937
by: peridian | last post by:
Hi, I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code. Most of the techniques I have seen for this involve complex use...
10
37259
by: webgirl | last post by:
Hi there, I've been searching the net & the forums here over the last few days for help with my problem & am getting myself really confused.. hoping someone may be able to help me here. I've...
0
7006
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5467
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4917
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
294
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.