Imports vb = Microsoft.VisualBasic
Public Class Form1
Public cad As String
Private Sub btnconvertir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnconvertir.Click
Dim x, y As String
Dim i, n, dec As Integer
dec = 0
x = vb.Trim(txtnum.Text)
n = vb.Len(x)
For i = 1 To n
y = vb.Mid(x, i, 1)
dec = dec + Val(y) * (2 ^ (n - i))
Next
txtresul.Text = dec
End Sub
Private Sub txtnum_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtnum.KeyPress
Select Case e.KeyChar
Case Chr(13) ' Enter
btnconvertir.Focus()
Case Chr(27) ' Escape
End
Case Chr(8) ' retroceso
Case "0" ' el cero
Case "1" ' el uno
Case Else
Beep() ' Beep, prendé los parlantes
e.Handled = True 'Impide el ingreso de caracteres ilegales
End Select
End Sub
Private Sub txtnum_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtnum.TextChanged
If txtnum.Text = "" Then
btnconvertir.Enabled = False
Else
btnconvertir.Enabled = True
End If
End Sub
Private Sub btnnuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnuevo.Click
txtnum.Text = ""
txtresul.Text = ""
txtnum.Focus()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class