by C.R.RAJAGOPAL STAR TECHNOLOGIES (3 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 28th June 2004
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
CONVERTING BINARY NUMBER TO DECIMAL
Dim T(500) As String
Dim W(500) As String
Dim Y(500) As Integer
Dim NUM As String
''place 3 command buttons one "clear",second "answer",third "quit" ''place two textboxes one to accept binary number and second to display decimal number as answer ''place two labels one "Binary no" before textbox1 and second "Decimal no" before textbox2
Snippet: Private Sub Cmdanswer_Click()
NUM = Text1.Text
L = Len(NUM)
For I = 1 To L
T(I) = Left(NUM, I)
Next I
For I = 1 To L
W(I) = Right(T(I), 1)
Next I
For I = 1 To L
Y(I) = Val(W(I))
Next I
Let S = 0
For I = L To 1 Step -1
S = S + Y(I) * (2 ^ (L - I))
Next I
Text2.Text = S
End Sub
Private Sub Cmdclear_Click()
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub
Private Sub Cmdquit_Click()
Unload Me
End
End Sub
Private Sub Form_Activate()
Text1.SetFocus
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
End Sub