Progress Bars With A Gradient

Progress Bars With A Gradient

The tip “Color Status Indicator” [“101 Tech Tips for VB Developers,” Supplement to the February 1997 issue of VBPJ, page 26] got me thinking that it would look even more attractive to have the status change color in gradient steps. Instead of changing the color at particular points, start at red, blend to orange, then yellow, and finally green.

To try this, place a Sheridan 3-D panel on your form and set the FloodType property to 1 (Left to Right) and ShowFloodPct to False. Place a command button and a text box (set the Caption to blank) on the form to do your testing. Place this code in the form:

 Private Sub Command1_Click()	Dim i As Integer, iIncrement As Integer	Dim iMidPoint As Integer, iCheckpoint As Integer	Dim j As Integer, sAddIncrement As String	Dim sSubIncrement As String	iIterations = Val(Text1)	iMidPoint = iIterations * 0.5 - 1	' find the midpoint	If iIterations / 510 = iIterations  510 Then		'perfect algorithm		iIncrement = 1		iCheckpoint = 1	ElseIf iIterations < 510 Then		'increment the color faster		iIncrement = 510  iIterations		iCheckpoint = 1	Else		'change the color less frequently		iIncrement = 1		iCheckpoint = iIterations  510 + 1	End If	sAddIncrement = "&H0000" & _		Format$(iIncrement, "00") & "00"	sSubIncrement = "&H0000" & _		Format$(iIncrement, "0000")	SSPanel1.FloodColor = &HFF	'start the panel at Red	'At your preference show the 	'percentage. However, the tighter 	'the loop, the less valuable this is.	SSPanel1.FloodShowPct = True	For i = 0 To iIterations - 1		'do your real processing here		If i / iCheckpoint = i  iCheckpoint Then			With SSPanel1				If i <= iMidPoint Then					.FloodColor = _						.FloodColor + sAddIncrement				Else					.FloodColor = _						.FloodColor - sSubIncrement				End If				.FloodPercent = (i + 1) / iIterations * 100			End With		End If		'if the loop is tight, be sure to 		'release the processor 		'occasionally - also, some flood		'controls (other than SSPanel) 		'may require this to get the 		'color updated in the control		DoEvents	Next	MsgBox "All done!", vbOKOnly + vbInformation	SSPanel1.FloodPercent = 0	SSPanel1.FloodShowPct = FalseEnd Sub

The effect works best when your video is set to at least 16-bit (High Color). Because there are exactly 510 progressive gradients between red and green, the number of iterations you enter will influence what shade of green you end up with. As the iterations increase (>900), you'll end up with bright green.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes