Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting RGB values
Message
From
17/08/1999 16:14:38
 
 
To
13/08/1999 18:31:33
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00253675
Message ID:
00254691
Views:
16
>Hi,
>
>Any code to convert RGB color values to VB color syntax?
>
> ie: RGB = 127,85,22 === VB code: BackColor="#FFFFFF" ??
>
>Any ideas would be appreciated...
>Thanks

This will work for you B}

create a form with a label named lblHex, a textbox named txtRGB and a command button called cmdConvert
Function RGBHexConvert(RGBString As String)
Dim iFirst, iSecond, iCount, iRedElement, iGreenElement, iBlueElement As Integer

'Initialize our variables
iFirst = 99
iSecond = 0

    'Loop through the
    For iCount = 1 To Len(RGBString)
        
        'Slowly I turned ... byte by by byte :)
        strCurElement = Mid(RGBString, iCount, 1)
            
            'define the position of the commas
            If strCurElement = "," Then
                If iFirst = 99 Then
                    'define the position of the first comma
                    iFirst = iCount
                Else
                    'define the position of the second comma
                    iSecond = iCount
                End If
            End If
    
    Next
        'Lets build our Hex value
        iRedElement = Val(Mid(RGBString, 1, (iFirst - 1)))
        iGreenElement = Val(Mid(RGBString, (iFirst + 1), (iSecond - 1)))
        iBlueElement = Val(Mid(RGBString, (iSecond + 1), Len(RGBString)))
    
    ' Lets format our output.
    RGBHexConvert = Format(Hex(iRedElement), "00") & Format(Hex(iGreenElement), "00") & Format(Hex(iBlueElement), "00")
End Function

Private Sub cmdConvert_Click()
lblHex.Caption = ("#" & RGBHexConvert(txtRGB.Text))
End Sub
~Joe Johnston USA

"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams

Previous
Next
Reply
Map
View

Click here to load this message in the networking platform