Tutoriales de Visual Basic

Introducción

Aquí esta este programa que convierte de binario a decimal, se tienen que pedir el número de bits que se quieran convertir.

Creamos el formulario y en el agregamos un botón (pedir), tres cajas de texto y tres etiquetas.
En el botón pedir es donde agregaremos todo el algoritmos para realizar la conversión.



Private sub cmdPedir_Click()
    Dim i As Integer, i2 As Integer, nu As Integer, base As Integer, su As Integer
    Dim sbits As String
    
    su = 0
    base = 0
    
    if IsNumeric(Text1.Text) Then
        nu = CInt(Text1.Text)
        
        For i = (nu - 1) To 0 Step -1
            v = InputBox("Escribe el bit")
            if v = 1 Or v = 0 Then
                sbits = sbits & v
            else
                i = i + 1
            end If
            if v = 1 Then
                if i = 0 Then
                    base = 1
                else
                    if i = 1 Then
                        base = 2
                    else
                        base = 2
                        For i1 = 1 To (i - 1)
                            base = base * 2
                        Next
                    end If
                end If
                su = su + (v * base)
            end If
        Next
    end If
    Text2.Text = sbits
    Text3.Text = su
end sub


Validamos la caja de texto donde pedimos los bits para que solo escriban números.



Private sub Text1_KeyPress(KeyAscii As Integer)
    if KeyAscii <> 8 Then
        if KeyAscii < 48 Or KeyAscii > 57 Then
            KeyAscii = 0
        end If
    end If
end sub


Autor: Gamaliel M. DescargarDescargar

Comentarios en "Conversor binario a decimal en visual"

Table 'programa_programas.t_comentarios' doesn't exist