From: Jim Y on 30 Sep 2006 19:37 "Steve Easton" <admin(a)95isalive.com> wrote in message news:OD3URIM5GHA.4616(a)TK2MSFTNGP05.phx.gbl... > Google for a utility named 3C color picker. > > It will do exactly what you want. > > -- > Steve Easton > > With the help and explanations given by other posters, I have the following which does the job. Thank you, Jim Option Explicit Private Sub Command1_Click() Dim k, rH, rR, rG, rB, HeStr, thisCh rH = UCase(Text1.Text) For k = 1 To 6 If Text1.Text Like "*[!0-9a-fA-F]*" Then MsgBox ("Invalid Characters in the Hex field!") Text1.Text = "" Exit Sub Else rB = CInt("&H" & Left$(rH, 2)) 'Blue hex source rG = CInt("&H" & Mid$(rH, 3, 2)) 'Green hex source rR = CInt("&H" & Right$(rH, 2)) 'Red hex source Text2.Text = rR 'Red value Text3.Text = rG 'Green value Text4.Text = rB 'Blue Me.BackColor = RGB(rR, rG, rB) End If Next k End Sub Private Sub Command2_Click() Unload Me End Sub Private Sub Form_Load() Me.Top = (Screen.Height - Me.Height) / 2 Me.Left = (Screen.Width - Me.Width) / 2 End Sub
From: Larry Serflaten on 30 Sep 2006 20:12 "Jim Y" <jj819stuffNOSPAM(a)comcast.net> wrote > With the help and explanations given by other posters, I have the following which does the job. And does it 6 times per button click! > For k = 1 To 6 <...> > Next k What is that loop for? The variable K is used nowhere else but as a loop counter. What would happen if you take it completely out of there? ;-) LFS
From: Rick Rothstein (MVP - VB) on 30 Sep 2006 20:22 Three points (see inline)... > With the help and explanations given by other posters, I have the > following which does the job. > Thank you, > Jim > Option Explicit > > Private Sub Command1_Click() > > > Dim k, rH, rR, rG, rB, HeStr, thisCh > > rH = UCase(Text1.Text) You don't need the above line as the If-Then expression using the Like operator allows for lower and upper case letters. > For k = 1 To 6 You do not need this loop any more. The loop originally existed to examine each character in the color string inputted into Text1... the If-Then expression using the Like operator tests all characters in Text1 in a single step. > If Text1.Text Like "*[!0-9a-fA-F]*" Then > MsgBox ("Invalid Characters in the Hex field!") > Text1.Text = "" > Exit Sub > Else > rB = CInt("&H" & Left$(rH, 2)) 'Blue hex source > rG = CInt("&H" & Mid$(rH, 3, 2)) 'Green hex source > rR = CInt("&H" & Right$(rH, 2)) 'Red hex source > > Text2.Text = rR 'Red value > Text3.Text = rG 'Green value > Text4.Text = rB 'Blue > > Me.BackColor = RGB(rR, rG, rB) > > End If > Next k If I understand what you are doing, you don't need any of the code above (well, maybe the test to make sure proper hex characters were typed into Text1), but you seem to have taken a round about way to use the color that you started with. Try this and see if it does what you want... Private Sub Command1_Click() If Text1.Text Like "*[!0-9a-fA-F]*" Then MsgBox ("Invalid Characters in the Hex field!") Text1.Text = "" Else Me.BackColor = "&H" & Text1.Text & "&" End If End Sub Rick
From: Jim Carlock on 30 Sep 2006 20:26 "Jim Y" <jj819stuffNOSPAM(a)comcast.net> wrote > With the help and explanations given by other posters, I have > the following which does the job. > For k = 1 To 6 > If Text1.Text Like "*[!0-9a-fA-F]*" Then > MsgBox ("Invalid Characters in the Hex field!") > Text1.Text = "" > Exit Sub > Else "Larry Serflaten" <serflaten(a)usinternet.com> wrote: > And does it 6 times per button click! > For k = 1 To 6 <...> > Next k It only displays that message box once though. <g> If he took that Exit Sub out of it though, that would correct that problem. -- Jim Carlock Post replies to the group.
From: Jim Y on 1 Oct 2006 10:18
"Rick Rothstein (MVP - VB)" <rickNOSPAMnews(a)NOSPAMcomcast.net> wrote in message news:OZxuh%23O5GHA.4476(a)TK2MSFTNGP04.phx.gbl... > Three points (see inline)... > >> With the help and explanations given by other posters, I have the following which does the job. >> Thank you, >> Jim >> Option Explicit >> >> Private Sub Command1_Click() >> >> >> Dim k, rH, rR, rG, rB, HeStr, thisCh >> >> rH = UCase(Text1.Text) > > You don't need the above line as the If-Then expression using the Like operator allows for lower > and upper case letters. > >> For k = 1 To 6 > > You do not need this loop any more. The loop originally existed to examine each character in the > color string inputted into Text1... the If-Then expression using the Like operator tests all > characters in Text1 in a single step. > >> If Text1.Text Like "*[!0-9a-fA-F]*" Then >> MsgBox ("Invalid Characters in the Hex field!") >> Text1.Text = "" >> Exit Sub >> Else >> rB = CInt("&H" & Left$(rH, 2)) 'Blue hex source >> rG = CInt("&H" & Mid$(rH, 3, 2)) 'Green hex source >> rR = CInt("&H" & Right$(rH, 2)) 'Red hex source >> >> Text2.Text = rR 'Red value >> Text3.Text = rG 'Green value >> Text4.Text = rB 'Blue >> >> Me.BackColor = RGB(rR, rG, rB) >> >> End If >> Next k > > If I understand what you are doing, you don't need any of the code above (well, maybe the test to > make sure proper hex characters were typed into Text1), but you seem to have taken a round about > way to use the color that you started with. Try this and see if it does what you want... > > Private Sub Command1_Click() > If Text1.Text Like "*[!0-9a-fA-F]*" Then > MsgBox ("Invalid Characters in the Hex field!") > Text1.Text = "" > Else > Me.BackColor = "&H" & Text1.Text & "&" > End If > End Sub > > Rick I did away with the loop after my previous posting. What I require is the rR, rG and rB. The Me.BackColor is for my visual comparison of the results. I use pencil and paper (some things don't need a computer) to record rR, rG and rB. For bmp graphics, I use the MS Paint and, in the Edit Colors, enter the RGB values into the Define Custom Colors chart. Prior to this original posting, it was all guess work on my part. Now I have the Hex and RGB equivalents for matching colors accurately. Again, thank you, Jim Y |