1 Replies - 20605 Views - Last Post: 12 June 2006 - 01:35 AM Rate Topic: -----

#1 StephanBotha  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 55
  • Joined: 12-March 06

Colours in VB6

Posted 12 June 2006 - 01:14 AM

Hi there,

Sorry for all these posts, but I'm making this list of questions as I go whilst attempting to learn VB6.

I've noticed that the colours in VB is not of the RGB or HEX standad. I use Macromedia Fireworks or Photoshop to get the HEX or RGB of a certain colour. How do I get the VB version of the RGB/HEX colours?

(FROM VB6 TO RGB & HEX)
VB Colour: &H00FF8090&

RGB->
Red: 144

Green:127

Blue:255


HEX: #907FFF

How do I get the colour from RGB or HEX to VB6?

Thanks in Advance!

Is This A Good Question/Topic? 0
  • +

#3 Nitish4uall  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 26
  • Joined: 19-April 06

Re: Colours in VB6

Posted 12 June 2006 - 01:35 AM

Here are some functions that you can use.

Public Sub Hex2RGB(strHexColor As String, r As Byte, g As Byte, b As Byte)
	Dim HexColor As String
	Dim i As Byte
	On Error Resume Next
	' make sure the string is 6 characters l
	'	 ong
	' (it may have been given in &H###### fo
	'	 rmat, we want ######)
	strHexColor = Right((strHexColor), 6)
	' however, it may also have been given a
	'	 s or #***** format, so add 0's in front


	For i = 1 To (6 - Len(strHexColor))
		HexColor = HexColor & "0"
	Next
	HexColor = HexColor & strHexColor
	' convert each set of 2 characters into 
	'	 bytes, using vb's cbyte function
	r = CByte("&H" & Right$(HexColor, 2))
	g = CByte("&H" & Mid$(HexColor, 3, 2))
	b = CByte("&H" & Left$(HexColor, 2))
End Sub


Public Function RGB2Hex(r As Byte, g As Byte, b As Byte) As String
	On Error Resume Next
	' convert to long using vb's rgb function, then use the long2rgb function
	RGB2Hex = Long2Hex(RGB(r, g, b))
End Function


Public Sub Long2RGB(LongColor As Long, r As Byte, g As Byte, b As Byte)
	On Error Resume Next
	' convert to hex using vb's hex function
	'	 , then use the hex2rgb function
	Hex2RGB (Hex(LongColor))
End Sub


Public Function RGB2Long(r As Byte, g As Byte, b As Byte) As Long
	On Error Resume Next
	' use vb's rgb function
	RGB2Long = RGB(r, g, b)
End Function


Public Function Long2Hex(LongColor As Long) As String
	On Error Resume Next
	' use vb's hex function
	Long2Hex = Hex(LongColor)
End Function


Public Function Hex2Long(strHexColor As String) As Long
	Dim r As Byte
	Dim g As Byte
	Dim b As Byte
	On Error Resume Next
	' use the hex2rgb function to get the red green and blue bytes
	Hex2RGB strHexColor, r, g, b
	' convert to long using vb's rgb function
	Hex2Long = RGB(r, g, b)
End Function




Hope that ypu can find them usefull..
Was This Post Helpful? 1

Page 1 of 1