Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Color fade to white using Pset

Posted on 2004-03-21
Last Modified: 2007-12-19

I need help with the logic to use pset to draw a color bar that fades from a given RGB to white over the scalewidth of a form.

Private Sub Command1_Click()

Dim r As Integer
Dim g As Integer
Dim b As Integer

r = 14
g = 67
b = 146

For i = 1 To Me.ScaleWidth Step 1
  For j = 1 To CInt(Me.ScaleHeight / 10) Step 10
     ' how do I increment the values of r,g,b to 255 relative to the ScaleWidth?
     ' if that makes sense?
     ' The idea is that r,g,b should arrive at 255 at about the same time.
    PSet (i, j), RGB(r, g, b)
  Next j
Next i

End Sub

Question by:Alan Warren
  • 2
  • 2

Accepted Solution

Nazdor earned 250 total points
ID: 10647575
Increment by: the difference / number of steps


dim rd as integer, gd as integer, bd as integer

rd = (255 - r) \ (me.scaleheight \ 10)
gd = (255 - g) \ (me.scaleheight \ 10)
bd = (255 - b) \ (me.scaleheight \ 10)

   r = r + rd
   g = g + gd
   b = b + bd

I've used "\" instead of "/" as "\" is integer divide, so you don't need CInt(), but you may find it works better using single for the colours + deltas (rd,gd,bd) then CInt ing them at the time of PSet

As a side, PSet is not going to be the quickest way to do this (it might be very slow) - you'll have to look into making API calls, but that's another subject.
LVL 26

Author Comment

by:Alan Warren
ID: 10653669
Hi Nazdor,

Thanks for that mate.

The speed is not an issue, it's just a tool for creating some background jpegs to be used for style switching with css.
So I hope to have half a dozen jpegs that fade from left to right 800px wide * 1px high that I can apply with Cascading Style Sheets like this. So achieving maximum impact with very little data transfer accross the WAN

    font:9pt Verdana, Tahoma, Arial, swiss, sans-serif;
    background: url("../images/header-background.jpg");
    background-repeat: repeat-y;   //* the repeat-y is like a fill down *//

Anyway after a bit of mucking around this is close enough to what I wanted.

Private Sub Command1_Click()
Dim r As Integer
Dim g As Integer
Dim b As Integer
Dim x As Integer

Dim iIncR As Integer
Dim iIncG As Integer
Dim iIncB As Integer

' 37,47,90
r = 37
g = 47
b = 90

x = CInt(Me.ScaleWidth / 156)

iIncR = CInt((255 - r))
iIncG = CInt((255 - g))
iIncB = CInt((255 - b))

For i = 1 To Me.ScaleWidth Step 1
  If (i + iIncR) Mod x = 0 Then: r = r + 1: 'Debug.Print r, g, b
  If (i + iIncG) Mod x = 0 Then: g = g + 1: 'Debug.Print r, g, b
  If (i + iIncB) Mod x = 0 Then: b = b + 1: 'Debug.Print r, g, b
  'If Me.ScaleWidth - i = 150 Then: Debug.Print Hex(r) & Hex(g) & Hex(b)
  For j = 1 To CInt(Me.ScaleHeight / 8)
    PSet (i, j), RGB(r, g, b)
  Next j
Next i

End Sub


Expert Comment

ID: 10662613
Sorry, should have looked quite a bit closer at your example - just assumed it was a kind of picture fades to white type of thing.  There are some cool api functions that might do what you want, just can't think of them off the top of my head.  But if you've got what you want, then there's no worry.
LVL 26

Author Comment

by:Alan Warren
ID: 10662657
Hi Nazdor,

Thanks for your help, it looks good, check it out.
Using binary large objects with Microsoft Access


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

829 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