Things You'll Need:
- Visual Basic 6.0 or Visual Basic Express
-
Step 1
Create an executable program in Visual Basic by opening the program and clicking on "File." Then click on "New Project" and choose the standard EXE type of project.
-
Step 2
Place a button on the form by double-clicking that tool in the Toolbox. Scan down the "Properties" pane on the right side and change the caption of the button to "Convert Decimal to Binary."
-
Step 3
Double-click on the button that now should read "Convert Decimal to Binary" to open the direct code-writing window. Type in the following commands between the "Private Sub Command1_Click()" and "End Sub" that you see:
Dim DecimalNbr As Long
DecimalNbr = InputBox("Enter the decimal number to convert to binary")
MsgBox ("The binary equivalent is " & BinaryNbr(DecimalNbr)) -
Step 4
Skip several lines after the above code and type the following:
Function ExpUp(ByVal exp As Long) As Long
Static interim(0 To 31) As Long, n As Integer
If interim(0) = 0 Then
interim(0) = 1
For n = 1 To 30
interim(n) = interim(n - 1) * 2
Next
interim(31) = &H80000000
End If
ExpUp = interim(exp)
End Function -
Step 5
Skip several lines below the above lines in the code and enter this:
Function BinaryNbr(ByVal calc As Long) As String
Dim interim As String, exp As Integer
interim = String$(32, "0")
Do
If calc And ExpUp(exp) Then
Mid$(interim, 32 - exp, 1) = "1"
calc = calc Xor ExpUp(exp)
End If
exp = exp + 1
Loop While calc
BinaryNbr = Mid$(interim, 33 - exp)
End Function -
Step 6
Press "F5" to run the application. Click on the "Enter decimal to binary" button. Enter any decimal number (whole) and press "Return." If you have entered the above code correctly, you will see the binary equivalent.
-
Step 7
Save the project and the form with an easily remembered name like "Binary Conversion." Then click "File" and "Make Binary Conversion.exe. Save the result on your desktop for easy access.










