Solved

# Binary convertion

Posted on 1998-07-25
240 Views
Can anyone tell me how to convert decimal to binary in VB?
0
Question by:twosons
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 2

Expert Comment

ID: 1466672
I assume you mean '7' -> 0000 0111

The usual way to do this is to see if it is odd then divide by 2 in a loop.
0

LVL 7

Accepted Solution

kamall earned 50 total points
ID: 1466673
On your form, put 2 text boxes and one command button. Copy and paste the following code in the general-declarations section of the form:

Private Sub Command1_Click()

DecValue = Val(Text1.Text)

BinValue = ""

Do
TempValue = DecValue Mod 2
BinValue = CStr(TempValue) + BinValue
DecValue = DecValue \ 2
Loop Until DecValue = 0

'Print
'Print BinValue

Text2.Text = BinValue

End Sub

Run the project, enter your number in the Text1 box and click the command button. Text2 text box will show the binary value of the number.

Hope that helps.
Regards
0

Author Comment

ID: 1466674
Thank you very much "kamall".  I knew the loop structure you have mentioned, but I was hoping to see if there is any other way to convert to binary, like "oct(number), hex(number)" in VB.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
###### Suggested Courses
Course of the Month3 days, 11 hours left to enroll