Sunday, September 7, 2008

Convert Binary Number To Decimal (VB6)

Public Function pow(base As Integer, power As Integer) As Long
Dim s As Long
s = 1
For i = 1 To power
s = s * base
Next
pow = s
End Function

Private Sub Form_Load()
Dim k As String
Dim j As Integer
Dim t As Byte
k = InputBox("Enter Number")
Dim i As Integer
i = 1
j = 0
While i <= Len(k)
t = Mid(k, i, 1)

j = j + t * pow(2, Len(k) - i)

i = i + 1
Wend
MsgBox j
End Sub

No comments: