Wednesday, March 25, 2009

Case 1: Decimal to Binary Converter and Calculator

DOWNLOAD COMPLETE FILE HERE.


Source Code:

Private Sub Add_Click()
num1& = Val(Text1.Text)
num2& = Val(Text2.Text)
Text3.Text = Val(num1&) + Val(num2&)

End Sub

Private Sub Convert_Click()
Dim num1 As Long, num2 As Long, num3 As Long
Dim bin1 As String, bin2 As String, bin3 As String

num1 = CLng(Val(Text1.Text))
Do While num1 > 0
bin1 = CStr(num1 Mod 2) + bin1
num1 = Int(num1 / 2)
Loop
Text4.Text = bin1

num2 = CLng(Val(Text2.Text))
Do While num2 > 0
bin2 = CStr(num2 Mod 2) + bin2
num2 = Int(num2 / 2)
Loop
Text5.Text = bin2

num3 = CLng(Val(Text3.Text))
Do While num3 > 0
bin3 = CStr(num3 Mod 2) + bin3
num3 = Int(num3 / 2)
Loop
Text6.Text = bin3
End Sub

Private Sub Divide_Click()
num1& = Val(Text1.Text)
num2& = Val(Text2.Text)
If num2& = 0 Then
MsgBox "Cant Divide by Zero"
Else
Text3.Text = Val(num1&) / Val(num2&)
End If
End Sub

Private Sub Form_Load()

End Sub

Private Sub Multiply_Click()
num1& = Val(Text1.Text)
num2& = Val(Text2.Text)
Text3.Text = Val(num1&) * Val(num2&)
End Sub

Private Sub Subtract_Click()
num1& = Val(Text1.Text)
num2& = Val(Text2.Text)
Text3.Text = Val(num1&) - Val(num2&)
End Sub

No comments:

Post a Comment