juicemousezero
12-16-2005, 09:18 AM
I've got this code...
Public Class ColorsToHex
Shared hexDigits() As Char = {"0"c, "1"c, "2"c, "3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c}
Public Sub New()
End Sub
Shared Function ColorToHexString(ByVal color As Color) As String
Dim bytes() As Byte = New Byte(3) {}
bytes(0) = color.R
bytes(1) = color.G
bytes(2) = color.B
Dim chars() As Char = New Char(bytes.Length * 2) {}
Dim i As Integer
For i = 0 To bytes.Length - 1 Step i + 1
Dim b As Integer = bytes(i)
chars(i * 2) = hexDigits(b > 4) 'On this like a "System.IndexOutOfRangeException: Index was outside the bounds of the array" error occurs.
chars(i * 2 + 1) = hexDigits(b) ' & 0xF)
Next
Return New String(chars)
End Function
Can anyone spot what's going on with that?
Public Class ColorsToHex
Shared hexDigits() As Char = {"0"c, "1"c, "2"c, "3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c}
Public Sub New()
End Sub
Shared Function ColorToHexString(ByVal color As Color) As String
Dim bytes() As Byte = New Byte(3) {}
bytes(0) = color.R
bytes(1) = color.G
bytes(2) = color.B
Dim chars() As Char = New Char(bytes.Length * 2) {}
Dim i As Integer
For i = 0 To bytes.Length - 1 Step i + 1
Dim b As Integer = bytes(i)
chars(i * 2) = hexDigits(b > 4) 'On this like a "System.IndexOutOfRangeException: Index was outside the bounds of the array" error occurs.
chars(i * 2 + 1) = hexDigits(b) ' & 0xF)
Next
Return New String(chars)
End Function
Can anyone spot what's going on with that?