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
"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