A tough logical error

admin

Administrator
Staff member
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?Try out this links, it maybe helpfull for classes
<!-- m --><a class="postlink" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/creatingclasses.asp">http://msdn.microsoft.com/library/defau ... lasses.asp</a><!-- m -->
<!-- m --><a class="postlink" href="http://www.vbip.com/books/1861007167/chapter_7167_04.asp">http://www.vbip.com/books/1861007167/ch ... 167_04.asp</a><!-- m -->
 
Back
Top