1

I have a function that turns a Hex string from a textBox into a integer value for colors. The issue is that I cannot get the function to execute.

I have a break point inside the function that says the following on execute: "No executable code is associated with this line"

This happens even when I replace:

cDialog.CustomColors = New Integer() {HexToColor1(tbHeader.Text)}

With:

   Dim cat As Integer
   cat = HexToColor1(tbHeader.Text)

Here is what the partial code looks like:

Dim cDialog As New ColorDialog()

 Private Sub btnHeader_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHeader.Click
    cDialog.CustomColors = New Integer() {HexToColor1(tbHeader.Text)}
 End Sub


Private Function HexToColor1(ByVal hexString As String) As Integer
    Dim actColor As Integer
    Dim r, g, b As Integer
    r = 0
    g = 0
    b = 0
    If hexString.StartsWith("#") And hexString.Length = 7 Then
        r = Val(hexString.Substring(1, 2))
        g = Val(hexString.Substring(3, 2))
        b = Val(hexString.Substring(5, 2))
        actColor = r + g * 256 + b * 65536
    Else
        actColor = 0
    End If
    Return actColor
End Function

This happens even when the Function's scope is set to "Public"

EDIT:

I do not know wether this is a debugger issue or not. When removing the break point from inside the function the code still will not work.

2
  • How is the Val function supposed to know that is has to convert a hex number if the number contains only digits from 0 to 9? Try this instead: Dim c As Color = (New System.Web.UI.WebControls.WebColorConverter()).ConvertFromString("#0C1722") Commented Sep 10, 2013 at 17:28
  • That was a issue I ran across later. I used "b = Val("&H" & hexString.Substring(5, 2)) Commented Sep 11, 2013 at 17:14

1 Answer 1

2

I don't think it has anything to do with your code. I had the same issue and used this post to resolve my issue:

Visual Studio Breakpoint Warning

  • The code the debugger is using is different from the code that the application is running (this was my issue)
  • The pdb file that the debugger is using is different from the code that the application is running
  • The code the application is running has been optimized and debug information has been stripped out.
  • The code in which you have breakpoints on hasn't been loaded into the process yet (assuming the things above are not the culprits)
  • If you are attaching the debugger, pay attention to what .net framework it's attaching to (i've had issues with it using .net 4 when code was all .net 2.0)
  • The assembly you have is also in the GAC. This might happen if say you installed your program so you could debug it, but the installer put the dll in the GAC.
  • Remove the reference and re-add it. Typically this occurs when the project that is referenced is not in the solution, and VS will copy the dll from the bin directory of another project. You will know this was the issue when you try to re-add the reference, and can't find the project
  • Remove all break points in the program

When all else fails, restart the computer, start up the project & Clean / Rebuild and everything should be fine.

Sign up to request clarification or add additional context in comments.

2 Comments

@JacobGoulden Right, right now the code the debugger is using is different from the code that the application is running and will not execute the function. Try the steps I provided and it should solve the issue ... If this doesn't work, remove your break points and put another one when you call the function (not in it) and a popup will appear asking you if you want to use this code instead ... I believe you click yes and it will work.
Wait, removing all break points from the file made the code work. thank you so much you're a life saver!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.