"Val" Function not returning numeric value?

The "Val" statement is not doing what I think it should. The expected value of the "cb.Name" each time the MessageBox statement is executed can range from "cbo11" to "cbo46". However, each time the MessageBox shows a value of 0. I tried using the statement of "Val(cb.Name)" and that produced the same. I just need to show the numeric portion of the cb.Name.

    Private Sub cbo_Click(sender As Object, e As EventArgs) Handles cbo.Click
            Dim cb As CheckBox = DirectCast(sender, CheckBox)

            EH.ErrorMessage = String.Empty


        Catch ex As Exception
            EH.ErrorMessage = "Form3/cbo_Click() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try

        EH.ProcessMessages(Me, Me.sbr, EH.ErrorMessage)
    End Sub

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
converting cb011 to numeric will return 0. this function does not remove non-numeric characters from it
Éric MoreauSenior .Net ConsultantCommented:
maybe you can try:
dim number = val(Regex.Replace(cb.Name,"[^0-9]",""))

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
Hi BlakeMcKenna;

You could use this first version which will display the digits in the name where ever they are.

MessageBox.Show(Regex.Match(cb.Name, "\d+").ToString())

Open in new window

Or if the format of the name is always going to be the same you could use this one.


Open in new window

BlakeMcKennaAuthor Commented:
Thanks guys! Both of these options are viable.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.