Skip to main content
se eliminaron 5 caracteres en el cuerpo
Origen Enlace
Alejandro Caro
  • 1.1k
  • 17
  • 36
Private Sub Command3_Click()
    ' Procedimiento que convierte un número de Octal a Hexadecimal
    
    Dim octNumber, length As String
    Dim total, i, j, dec, modnum As Integer
    
    total = 0
    j = 0
    
    Dim oct As String
    
    octNumber = Val(Text1.Text)
    
    oct = octNumber
    length = Len(oct)
    
    Dim value As Boolean
    
    value = True
    
    For i = length - 1 To 0 Step -1
        dec = 0
        
        Select Case (Str(i))
            Case 0
                dec = 0
            Case 1
                dec = CInt(8 ^ j)
            Case 2
                dec = CInt(8 ^ j) * 2
            Case 3
                dec = CInt(8 ^ j) * 3
            Case 4
                dec = CInt(8 ^ j) * 4
            Case 5
                dec = CInt(8 ^ j) * 5
            Case 6
                dec = CInt(8 ^ j) * 6
            Case 7:
                dec = CInt(8 ^ j) * 7
            Case Else
                value = False
        End Select
        total = total + dec
        j = j + 1
    Next
    
    If value Then
        Dim hexa As String
        hexa = ""
        If total > 0 Then
            While (total > 0)
                modnum = CInt(total Mod 16)
                total = total \ 16
                Select Case (modnum)
                    Case 0
                        hexa = "0" & hexa
                    Case 1
                        hexa = "1" & hexa
                    Case 2
                        hexa = "2" & hexa
                    Case 3
                        hexa = "3" & hexa
                    Case 4
                        hexa = "4" & hexa
                    Case 5
                        hexa = "5" & hexa
                    Case 6
                        hexa = "6" & hexa
                    Case 7
                        hexa = "7" & hexa
                    Case 8
                        hexa = "8" & hexa
                    Case 9
                        hexa = "9" & hexa
                    Case 10
                        hexa = "A" & hexa
                    Case 11
                        hexa = "B" & hexa
                    Case 12:
                        hexa = "C" & hexa
                    Case 13:
                        hexa = "D" & hexa
                    Case 14:
                        hexa = "E" & hexa
                    Case 15:
                        hexa = "F" & hexa
                End Select
            Wend
            Text2.Text = hexa
    
            ElseIf total = 0 Then
                Text2.Text = "0"
            ElseIf Not hexa Then
                Text2.Text = "Dato erróneo"
            Else
                Text2.Text = "Dato erróneo"
            End If
        End If
End Sub
Private Sub Command3_Click()
    ' Procedimiento que convierte un número de Octal a Hexadecimal
    
    Dim octNumber, length As String
    Dim total, i, j, dec, modnum As Integer
    
    total = 0
    j = 0
    
    Dim oct As String
    
    octNumber = Val(Text1.Text)
    
    oct = octNumber
    length = Len(oct)
    
    Dim value As Boolean
    
    value = True
    
    For i = length - 1 To 0 Step -1
        dec = 0
        
        Select Case (Str(i))
            Case 0
                dec = 0
            Case 1
                dec = CInt(8 ^ j)
            Case 2
                dec = CInt(8 ^ j) * 2
            Case 3
                dec = CInt(8 ^ j) * 3
            Case 4
                dec = CInt(8 ^ j) * 4
            Case 5
                dec = CInt(8 ^ j) * 5
            Case 6
                dec = CInt(8 ^ j) * 6
            Case 7:
                dec = CInt(8 ^ j) * 7
            Case Else
                value = False
        End Select
        total = total + dec
        j = j + 1
    Next
    
    If value Then
        Dim hexa As String
        hexa = ""
        If total > 0 Then
            While (total > 0)
                modnum = CInt(total Mod 16)
                total = total \ 16
                Select Case (modnum)
                    Case 0
                        hexa = "0" & hexa
                    Case 1
                        hexa = "1" & hexa
                    Case 2
                        hexa = "2" & hexa
                    Case 3
                        hexa = "3" & hexa
                    Case 4
                        hexa = "4" & hexa
                    Case 5
                        hexa = "5" & hexa
                    Case 6
                        hexa = "6" & hexa
                    Case 7
                        hexa = "7" & hexa
                    Case 8
                        hexa = "8" & hexa
                    Case 9
                        hexa = "9" & hexa
                    Case 10
                        hexa = "A" & hexa
                    Case 11
                        hexa = "B" & hexa
                    Case 12:
                        hexa = "C" & hexa
                    Case 13:
                        hexa = "D" & hexa
                    Case 14:
                        hexa = "E" & hexa
                    Case 15:
                        hexa = "F" & hexa
                End Select
            Wend
            Text2.Text = hexa
    
            ElseIf total = 0 Then
                Text2.Text = "0"
            ElseIf Not hexa Then
                Text2.Text = "Dato erróneo"
            Else
                Text2.Text = "Dato erróneo"
            End If
        End If
End Sub
Private Sub Command3_Click()
    ' Procedimiento que convierte un número de Octal a Hexadecimal
    
    Dim octNumber, length As String
    Dim total, i, j, dec, modnum As Integer
    
    total = 0
    j = 0
    
    Dim oct As String
    
    octNumber = Val(Text1.Text)
    
    oct = octNumber
    length = Len(oct)
    
    Dim value As Boolean
    
    value = True
    
    For i = length - 1 To 0 Step -1
        dec = 0
        
        Select Case (Str(i))
            Case 0
                dec = 0
            Case 1
                dec = CInt(8 ^ j)
            Case 2
                dec = CInt(8 ^ j) * 2
            Case 3
                dec = CInt(8 ^ j) * 3
            Case 4
                dec = CInt(8 ^ j) * 4
            Case 5
                dec = CInt(8 ^ j) * 5
            Case 6
                dec = CInt(8 ^ j) * 6
            Case 7
                dec = CInt(8 ^ j) * 7
            Case Else
                value = False
        End Select
        total = total + dec
        j = j + 1
    Next
    
    If value Then
        Dim hexa As String
        hexa = ""
        If total > 0 Then
            While (total > 0)
                modnum = CInt(total Mod 16)
                total = total \ 16
                Select Case (modnum)
                    Case 0
                        hexa = "0" & hexa
                    Case 1
                        hexa = "1" & hexa
                    Case 2
                        hexa = "2" & hexa
                    Case 3
                        hexa = "3" & hexa
                    Case 4
                        hexa = "4" & hexa
                    Case 5
                        hexa = "5" & hexa
                    Case 6
                        hexa = "6" & hexa
                    Case 7
                        hexa = "7" & hexa
                    Case 8
                        hexa = "8" & hexa
                    Case 9
                        hexa = "9" & hexa
                    Case 10
                        hexa = "A" & hexa
                    Case 11
                        hexa = "B" & hexa
                    Case 12
                        hexa = "C" & hexa
                    Case 13
                        hexa = "D" & hexa
                    Case 14
                        hexa = "E" & hexa
                    Case 15
                        hexa = "F" & hexa
                End Select
            Wend
            Text2.Text = hexa
    
            ElseIf total = 0 Then
                Text2.Text = "0"
            ElseIf Not hexa Then
                Text2.Text = "Dato erróneo"
            Else
                Text2.Text = "Dato erróneo"
            End If
        End If
End Sub
Origen Enlace
Alejandro Caro
  • 1.1k
  • 17
  • 36

Convertir de octal a Hexadecimal en Visual Basic 6.0 sin usar otras funciones de conversión ya definidas

Tengo este código en un Command1 que pretende convertir en número de octal a Hexadecimal.
El tema es que da siempre 0 y no se corregirlo. ¿Cómo se puede solventar el error?

Private Sub Command3_Click()
    ' Procedimiento que convierte un número de Octal a Hexadecimal
    
    Dim octNumber, length As String
    Dim total, i, j, dec, modnum As Integer
    
    total = 0
    j = 0
    
    Dim oct As String
    
    octNumber = Val(Text1.Text)
    
    oct = octNumber
    length = Len(oct)
    
    Dim value As Boolean
    
    value = True
    
    For i = length - 1 To 0 Step -1
        dec = 0
        
        Select Case (Str(i))
            Case 0
                dec = 0
            Case 1
                dec = CInt(8 ^ j)
            Case 2
                dec = CInt(8 ^ j) * 2
            Case 3
                dec = CInt(8 ^ j) * 3
            Case 4
                dec = CInt(8 ^ j) * 4
            Case 5
                dec = CInt(8 ^ j) * 5
            Case 6
                dec = CInt(8 ^ j) * 6
            Case 7:
                dec = CInt(8 ^ j) * 7
            Case Else
                value = False
        End Select
        total = total + dec
        j = j + 1
    Next
    
    If value Then
        Dim hexa As String
        hexa = ""
        If total > 0 Then
            While (total > 0)
                modnum = CInt(total Mod 16)
                total = total \ 16
                Select Case (modnum)
                    Case 0
                        hexa = "0" & hexa
                    Case 1
                        hexa = "1" & hexa
                    Case 2
                        hexa = "2" & hexa
                    Case 3
                        hexa = "3" & hexa
                    Case 4
                        hexa = "4" & hexa
                    Case 5
                        hexa = "5" & hexa
                    Case 6
                        hexa = "6" & hexa
                    Case 7
                        hexa = "7" & hexa
                    Case 8
                        hexa = "8" & hexa
                    Case 9
                        hexa = "9" & hexa
                    Case 10
                        hexa = "A" & hexa
                    Case 11
                        hexa = "B" & hexa
                    Case 12:
                        hexa = "C" & hexa
                    Case 13:
                        hexa = "D" & hexa
                    Case 14:
                        hexa = "E" & hexa
                    Case 15:
                        hexa = "F" & hexa
                End Select
            Wend
            Text2.Text = hexa
    
            ElseIf total = 0 Then
                Text2.Text = "0"
            ElseIf Not hexa Then
                Text2.Text = "Dato erróneo"
            Else
                Text2.Text = "Dato erróneo"
            End If
        End If
End Sub