DateDiff Function (2 Viewers)

Dick7Access

Dick S
Local time
Today, 04:34
Joined
Jun 9, 2009
Messages
4,201
I gave you a link in my prior post. That will convert a decimal to a Hex number.

A color string needs to be 6 characters:

FF9900

The first two (FF) designate the red value, the second two (99) designate green and the last two (00) designate blue. An issue you might run into is that the Hex function doesn't pad 0's onto the left. So Hex(7) will return 7 and not 07. You would have to catch that and pad it with the 0 to make your final string 6 characters.
Also, its a 256 color pallet, meaning if the user inputs 312 for green, its an invalid input. They can only input numbers 0-255 for valid colors.

Thanks for answering. I went to the link many times, but I couldn't grasp the concept. Your post look like I might get it, but I haven't look it over yet, as I am feeding my face right now. Nuts! just got mustard on my key board!!!:eek:
 

Dick7Access

Dick S
Local time
Today, 04:34
Joined
Jun 9, 2009
Messages
4,201
Code:
RedHex = Hex(Me.PickRed)
  If RedHex < 9 Then
 RedHex = Format(RedHex, "00")
         
  Else: RedHex = RedHex
   End If

DoCmd.GoToControl "txtHexRed"
Me.txtHexRed.Text = RedHex
This works fine 1 to 9, pads my "0",10 or higher gives me run time error 13 mismatch.
what am I missing?
 

plog

Banishment Pending
Local time
Today, 03:34
Joined
May 11, 2011
Messages
11,646
Hex=Base 16. Base 16 uses A-F for numbers 10-15. So,

Hex(11) is returning "B".
B<9 doesn't make sense.

My advice is to test RedHex for string length not value. Less than 2 characters, pad with a 0; if 2 characters, no padding.
 

Dick7Access

Dick S
Local time
Today, 04:34
Joined
Jun 9, 2009
Messages
4,201
Thanks for your help. Padding zeros working fine with this code for 1 thru 9 and 16 thru 255
What do I do with 10 thru 15? I don’t even know what to goggle.
Code:
    Dim RedHex As String
  Dim LRedResult As Long
  RedHex = Hex(Me.PickRed)
  LResult = Len(RedHex)
    If LRedResult < 2 Then
    RedHex = Format(RedHex, "00") 
     Else: RedHex = RedHex
     End If
  DoCmd.GoToControl "txtHexRed"
  Me.txtHexRed.Text = RedHex
 

plog

Banishment Pending
Local time
Today, 03:34
Joined
May 11, 2011
Messages
11,646
Instead of Format, just concatenate a 0:

RedHex = "0" & RedHex
 

Dick7Access

Dick S
Local time
Today, 04:34
Joined
Jun 9, 2009
Messages
4,201
I have goggled for 3 hours. Every thing works fine except last line.
Code:
Option Compare Database


Dim RedHex As String
Dim LRedResult As Long

Dim GreenHex As String
Dim LGreenResult As Long

Dim BlueHex As String
Dim LBlueResult As Long

Dim AllThree As String

'----------------------------------
'Red
'-----------------------------------------
Private Sub cmdPickColor_Click()
RedHex = Hex(Me.PickRed)
LRedResult = Len(RedHex)

  If LRedResult < 2 Then
       RedHex = "0" & RedHex
 
   Else: RedHex = RedHex
   End If

DoCmd.GoToControl "txtHexRed"
Me.txtHexRed.Text = RedHex

'-------------------------------------
'Green
'-------------------------------------
GreenHex = Hex(Me.PickGreen)
LGreenResult = Len(GreenHex)

If LGreenResult < 2 Then
    GreenHex = "0" & GreenHex
    
   Else: GreenHex = GreenHex
  End If
DoCmd.GoToControl "txtHexgreen"
Me.txtHexGreen = GreenHex

'-----------------------------------------
'Blue
'--------------------------------
BlueHex = Hex(Me.PickBlue)
LBlueResult = Len(BlueHex)
 If LBlueResult < 2 Then
    BlueHex = "0" & BlueHex
 
   Else: BlueHex = BlueHex
   End If
DoCmd.GoToControl "txtHexBlue"
Me.txtHexBlue = BlueHex

AllThree = "#" & RedHex & GreenHex & BlueHex
DoCmd.GoToControl "testLresult"
testLresult.Text = AllThree
Me.Detail.BackColor = AllThree   ' this line crashes

End Sub
 

Dick7Access

Dick S
Local time
Today, 04:34
Joined
Jun 9, 2009
Messages
4,201
Thanks All, Got it!
Yes:
Code:
AllThree = RedHex & GreenHex & BlueHex
No:
Code:
AllThree = “#” & RedHex & GreenHex & BlueHex
 

Users who are viewing this thread

Top Bottom