From: Sneha Menon on 30 Sep 2006 02:36 Jim Y wrote: > How do I get the color value? I have the hex value. > > Jim Y > > -------------------------------------------------------------------------------------- Hi Jim This is something dug out of my learning-vb time files. Havent modified or optimized thereafter. Anyway this will suit your need. Put 4 Text boxes and command button on a form Enter Hex value in Text1 and press the button You will get the RGB values in the other --------------Code------------------------------- Private Sub Command1_Click() Dim k, rH, rR, rG, rB, HeStr, thisCh HeStr = "0123456789ABCDEF" rH = UCase(Text1.Text) For k = 1 To 6 thisCh = Mid(rH, k, 1) If InStr(HeStr, thisCh) < 1 Then MsgBox ("Invalid Characters in the Hex field!") Else rR = (((InStr(1, HeStr, Mid(rH, 1, 1)) - 1) * 16)) + (InStr(1, HeStr, Mid(rH, 2, 1)) - 1) rG = (((InStr(1, HeStr, Mid(rH, 3, 1)) - 1) * 16)) + (InStr(1, HeStr, Mid(rH, 4, 1)) - 1) rB = (((InStr(1, HeStr, Mid(rH, 5, 1)) - 1) * 16)) + (InStr(1, HeStr, Mid(rH, 5, 1)) - 1) Text2.Text = rR 'Red value Text3.Text = rG 'Green value Text4.Text = rB 'Blue End If Next k End Sub ----------------------------Code End------------------ Let me know whether it solved your problem Regards Sneha ---------------------------------------------------------------------------------------
From: Rick Rothstein (MVP - VB) on 30 Sep 2006 10:35 Two comments about your code... > HeStr = "0123456789ABCDEF" > rH = UCase(Text1.Text) > > thisCh = Mid(rH, k, 1) > If InStr(HeStr, thisCh) < 1 Then The above for testing whether the TextBox contains acceptable hex characters can be replaced with this... If Text1.Text Like "*[!0-9a-fA-F]*" Then > rR = (((InStr(1, HeStr, Mid(rH, 1, 1)) - 1) * 16)) + (InStr(1, HeStr, > Mid(rH, 2, 1)) - 1) > rG = (((InStr(1, HeStr, Mid(rH, 3, 1)) - 1) * 16)) + (InStr(1, HeStr, > Mid(rH, 4, 1)) - 1) > rB = (((InStr(1, HeStr, Mid(rH, 5, 1)) - 1) * 16)) + (InStr(1, HeStr, > Mid(rH, 5, 1)) - 1) You have an error in the code for calculating rB... your two Mid function calls select the same character (the 5th one in rH) instead of the 5th and 6th characters from the rH string variable. The rB value of 204 that your code produces (for the OP's first example input of "FFFFC0") is incorrect. Changing the 5 in the last Mid function call to 6 makes the statement produce the correct value for rB of 192. By the way, if you want to perform these string calculation using String manipulations, which is a slower method (only significant if the calculations are being done in a large loop) than using numerical calculations I posted earlier, you could create much simpler statements like these... rR = CInt("&H" & Left$(rH, 2)) rG = CInt("&H" & Mid$(rH, 3, 2)) rB = CInt("&H" & Right$(rH, 2)) which produce the same results as your statements do (once the last statement is correct as shown above). Rick
From: Sneha Menon on 30 Sep 2006 11:47 Rick Rothstein (MVP - VB) wrote: > Two comments about your code... > > > HeStr = "0123456789ABCDEF" > > rH = UCase(Text1.Text) > > > > thisCh = Mid(rH, k, 1) > > If InStr(HeStr, thisCh) < 1 Then > > The above for testing whether the TextBox contains acceptable hex characters > can be replaced with this... > > If Text1.Text Like "*[!0-9a-fA-F]*" Then ------------------------------------------------------------------------------ Hi Rick I confessed in the first place it is a non-optimized learner-kit stuff *This is something dug out of my learning-vb time files. Havent modified or optimized thereafter. * Thanks for pointing out the 5/6 error.. That creeped in while copy-pasting certain portions; missed to change the 5 to 6. Anyway, the OP got an idea to base his strategy on. That much good. Regards Rick. Sneha ----------------------------------------------------------------------------
From: Rick Rothstein (MVP - VB) on 30 Sep 2006 11:53 >> > HeStr = "0123456789ABCDEF" >> > rH = UCase(Text1.Text) >> > >> > thisCh = Mid(rH, k, 1) >> > If InStr(HeStr, thisCh) < 1 Then >> >> The above for testing whether the TextBox contains acceptable hex >> characters >> can be replaced with this... >> >> If Text1.Text Like "*[!0-9a-fA-F]*" Then > ------------------------------------------------------------------------------ > Hi Rick > > I confessed in the first place it is a non-optimized learner-kit stuff > > *This is something dug out of my learning-vb time files. > Havent modified or optimized thereafter. * Not a problem... I was just trying to add to your knowledgebase. > Thanks for pointing out the 5/6 error.. > That creeped in while copy-pasting certain portions; missed to change > the 5 to 6. Yeah, I hate when that happens to me in my own postings. > Anyway, the OP got an idea to base his strategy on. That much good. Correct. Rick
From: Steve Easton on 30 Sep 2006 14:54
Google for a utility named 3C color picker. It will do exactly what you want. -- Steve Easton "Jim Y" <jj819stuffNOSPAM(a)comcast.net> wrote in message news:uYCdndgesrWERYDYnZ2dnUVZ_v6dnZ2d(a)comcast.com... > VB6 uses hexadecimals to define color of forms and text. Is there a program or some way > that I can obtain the following for these 4 colors? > > Light Blue = &H00FFFFC0& > Light Yellow = &H00C0FFFF& > Light Red = &H00C0C0FF& > Light Green = &H00C0FFC0& > > I need the Hue, Sat, Lum, Red, Green and Blue numerical values of each color. > > I am creating some small graphics and want to color match the background when the > graphic is placed on an Image Control. Consider the graphic to be a silver oval in a > rectangle. Unfortunately, I cannot make the background transparent with the software > that I am using. I would prefer a method that will permit me to use any color in the > future. > > Thank you, > Jim Y > > |