Attribute VB_Name = "mdl_rgb_rndm" ' Replace imgsource with the pic/img box name ' Replace frmMain with the name of the form containing imgsource ' Add a timer interval=1,reference ColorUpdate() ' Replace Timer1 with the name of the timer. ' Add call to InitializeColors() in frmMain.load ' c_INITIALINTERVAL applies to first scan when no colors are changed ' c_RUNINTERVAL applies to all subsequent scans ' c_WAITINTERVAL set the period between scans Option Explicit Private Const c_RUNINTERVAL As Integer = 1 ' 20 Private Const c_INITIALINTERVAL As Integer = 1 Private Const c_WAITINTERVAL As Integer = 1 ' 10000 Private m_intW As Integer, m_intH As Integer Private m_intL As Integer, m_intT As Integer Private Y As Integer, k As Integer, X As Integer Private r As Long, g As Long, b As Long Private m_intDelta As Integer Private m_bolRunning As Boolean Private Declare Function GetSysColor Lib "user32" _ (ByVal nIndex As Long) As Long Public Sub InitializeColors() frmMain.Timer1.Interval = c_INITIALINTERVAL m_bolRunning = False With frmMain.imgSource m_intL = .Left m_intT = .Top m_intW = m_intL + .Width m_intH = m_intT + .Height End With Y = m_intT k = 1 End Sub Public Sub ColorUpdate() If m_bolRunning Then frmMain.Timer1.Interval = c_RUNINTERVAL End If If Y > m_intH Or Y < m_intT Then Randomize m_intDelta = Int(256 * Rnd) k = -1 * k Y = Y + k frmMain.Timer1.Interval = c_WAITINTERVAL m_bolRunning = True End If For X = m_intL To m_intW Call BreakColor(frmMain.Point(X, Y), r, g, b) frmMain.PSet (X, Y), RGB(r, g, b) Next Y = Y + k End Sub ' Break a color into is components. Private Sub BreakColor(ByVal color As Long, ByRef r As Long, _ ByRef g As Long, ByRef b As Long) If color = &HFFFFFFFF Then color = GetSysColor(color And &HFFFFFF) End If r = color And &HFF& g = (color And &HFF00&) \ &H100& b = (color And &HFF0000) \ &H10000 r = (r + m_intDelta) Mod 256 g = (g + m_intDelta) Mod 256 b = (b + m_intDelta) Mod 256 End Sub