A+ code: convert numbers to and from decimal, hexadecimal and octal
Posted: 2002-06-01
By: ArchiveBot
Viewed: 81
Filed Under:
No attachments for this post
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
Original Author: erLog
Assumptions
You need a txtNumber text box for the number display, and then three check boxes (optDecimalButton, optHexButton and optOctalButton). That's it!
Code
'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
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.