Code Snippets VB.Net

VB.Net - Convert Hexadecimal String to Decimal (Integer).

IncludeHelp VB.Net 13 OCT 2016

In this VB.Net code we will learn how to convert a hexadecimal string into its equivalent decimal integer value?

In this example we created a sample form with two components textbox and button, conversion operation will be performed on button click event and value will be entered in textbox.

To convert Hexadecimal string to decimal integer value we used CInt() Method which will convert given Hexadecimal value to integer.

Here is the syntax

CInt("&H" & "hex_value")

VB.Net Code - Convert Hexadecimal String to Decimal (Integer)

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'get the value from text box - value should be in hex string

        Dim hexString As String = Nothing

        hexString = TextBox1.Text.Trim

        'convert into decimal
        Dim decValue As Integer = 0

        decValue = CInt("&H" & hexString)

        MsgBox("Integer value is: " & decValue)

    End Sub
End Class

Output

convert hex to integer in vb.net




Copyright © 2024 www.includehelp.com. All rights reserved.