Code Repository question

Tango

DB/Application Dev Newbie
Local time
Today, 10:24
Joined
Jun 23, 2011
Messages
141
I got this code from the code repository on this site titled "Color Drifting". I could use a little help getting it to work though.

Does anyone know why I would be getting an error "function not defined" on RGBfromLongColor when I put this code in the on timer event?

http://www.access-programmers.co.uk/forums/showthread.php?t=211839
 
Hi,

It looks like there is erroneous text in the procedure name. Try removing the space and "RGB" from the procedure name

Change this:
Code:
Sub RGBfromLongColor RGB(lColor As Long, iR As Integer, iG As Integer, iB As Integer)
to
Code:
Sub RGBfromLongColor(lColor As Long, iR As Integer, iG As Integer, iB As Integer)
 
That fixed THAT problem, thank you. Unfortunetly now the code runs but the color of the object selected doesnt change. It just "flickers" so far but no errors are generated. I suspect it could be a problem with the code logic rather than implementation at this point.

Any thoughts? I am doing this more to help myself learn vba than anything else.
 
what interval did you set on the timer. try different ones
 
Hi,

I haven't had time to look at the code thoroughly. The RGBFromLongColor procedure is attempting to modify the values of iR, iG, and iB respectively. This works because by default access passes the variables by reference (ByRef). When the variable is changed ny RGBfromLongColor the modified value is then passed back to the calling procedure.

It might be worth explicitly stating this like the following so it is clear that the parameters will be passed back:

Sub RGBfromLongColor(lColor As Long, ByRef iR As Integer, ByRef iG As Integer, ByRef iB As Integer)

This is a useful feature, but be aware that this can make debugging the code quite hard. In more complex examples it is not always obvious that the variables have been modified when looking at the main procedure.

Try checking the properties for your form and looking at the Event tab. You will see a Timer Interval setting, which is the delay in milliseconds used by the OnTimer event.

By setting this value you will adjust how frequently the colour changes. If this is set to a very low value then the form would not have time to update properly and this may be causing the flicker.
 
ok, i can see what it is doing. i put this on a form, and added some text boxes to see what the colour values were doing

given a "grey" colour of

R = 130
G = 130
B = 130 to start with

each colour is randomly amended either up or down by 1, for each timer event

so instead of

R 130
G 130
B 130

it might go to

R 129
G 131
B 131

(like a drunkards walk)

the trouble is you can hardly see any change with changes of just 1

instead set the form timer to 100, say - seems to be a good value
and change the code in sub driftcolor to do +25 and -25 instead of +1 and -1

so now
R 130
G 130
B 130


might go to

R 105
G 155
B 155

then you will see the colour change as the timer fires.

as the OP said, not so useful, but shows you a few VBA things.
 
Awsome replies from all. I tried diferent time intervals with no effect but changing the value it jumps by from +/-1 to instead be +/- 50 produced the desired result.

Thanks again all!
 
I tried again.

it's the +/- 1 thats the trouble. it just doesn't move very far away from its start value, enough to see a significant change.

even using just +/-5 or +/-10, with a timer of 10 produces a clear effect.
 

Users who are viewing this thread

Back
Top Bottom