VB icon

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

Email
Submitted on: 1/16/2015 5:08:00 PM
By: erLog (from psc cd)  
Level: Beginner
User Rating: By 9 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0, VB Script
Views: 2203
 
     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
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: A+ code: convert numbers to and from decimal, hexadecimal and octal
' Description: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
' By: erLog (from psc cd)
'
' Assumes:You need a txtNumber text box for the number display, and then three check boxes (optDecimalButton, optHexButton and optOctalButton). That's it!
'**************************************

'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


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.