VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A+ code: convert numbers to and from decimal, hexadecimal and octal

by erLog (3 Submissions)
Category: Math/Dates
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (9 Votes)

This code will convert numbers to and from decimal, hexadecimal and octal. It's really useful and simple to follow code - intended for the beginner. If you use it, there's no need to give me credit but lease vote for it, thanks.
-lgr

Assumes
You need a txtNumber text box for the number display, and then three check boxes (optDecimalButton, optHexButton and optOctalButton). That's it!

Rate A+ code: convert numbers to and from decimal, hexadecimal and octal

'Written by littlegreenrussian
Sub optDecimalButton_click() 'decimal checkbox clicked
txtNumber.Text = Format(CurrentNum) 'change the format of the txtHumber textbox
End Sub

Sub optHexButton_click() 'hexadecimal checkbox clicked
txtNumber.Text = Format(CurrentNum) 'change the format of the txtHumber textbox
End Sub

Sub optOctalButton_click() 'octalcheckbox clicked
txtNumber.Text = Format(CurrentNum) 'change the format of the txtHumber textbox
End Sub

SubtxtNumber_Change()
'Val function - numbers beginning with &O as octal,
'numbers beginning with &H as hexadecimal
If optOctalButton.Value = True Then 'octal button checked
CurrentNum = Val("&O" & LTrim(txtNumber.Text)& "&") 'change the number to octal
Else if optDecimal.Value = True Then 'decimal checked
CurrentNum = Val(LTrim(txtNumber.Text)& "&") 'change number to deciaml - note it does NOT require a &D
Else 'otherwise
CurrentNum = Val("&H" & LTrim(txtNumber.Text)& "&") 'change it to hexadecimal
End If
End Sub

Download this snippet    Add to My Saved Code

A+ code: convert numbers to and from decimal, hexadecimal and octal Comments

No comments have been posted about A+ code: convert numbers to and from decimal, hexadecimal and octal. Why not be the first to post a comment about A+ code: convert numbers to and from decimal, hexadecimal and octal.

Post your comment

Subject:
Message:
0/1000 characters