Search from Cycling Blog

Converting decimal number into Hexadecimal number[VB.NET]

Converting decimal number into Hexadecimal number

Language: VB.NET

Author: Aamir Mustafa

E-Mail: aamir_mustafa2007@msn.com

aamirmustafa134@gmail.com

Introduction:

This article will show you how to convert a decimal number into Hexadecimal number.


How to Use:

Create an empty project

On the form, add a button, two textboxes

  1. btnHexadecimal
  2. txtNum
  3. txtHexadecimal

We will take input through txtNum and show Hexadecimal number into txtHexadecimal and we will use btnHexadecimal for converting decimal into Hexadecimal.

Write following code in btn Hexadecimal Click event

[code]

Private Sub btnHexadecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHexadecimal.Click

Try

Dim num As Long 'number that we will take through input

num = CLng(txtNum.Text) 'assigning textbox value to num and converting string value to long using CLng function

If IsNumeric(num) Then 'checking that text box contains numeric value

txtHexadecimal.Text = Convert.ToString(num, 16) 'here 16 means converting to hexadecimal

End If

Catch ex As Exception

MessageBox.Show("Plz enter the number", "Octal", MessageBoxButtons.OK, MessageBoxIcon.Information)

txtNum.Focus()

End Try

End Sub

 

0 comments: