Jump to content

Exibir um numero numa ordem inversa em pares


Joca
 Share

Recommended Posts

Queria inverter um numero hexadecimal, como o referido no exemplo seguinte usando o número "354".

Dá para fazer essa inversão aos pares:

-> com uma função simples já disponível no Vb2005;

-> ou, com várias funções "Mid";

-> ou estou condenado a algo mais complexo?...

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' Se eu escrevo "354" na RichTextBox1Decimal, 
        ' então, tenho de obter "62010000" na RichTextBox3HexInvertido...

        If RichTextBox1Decimal.Text = "" And RichTextBox2Hex.Text = "" Then

            MsgBox("Tem de introduzir valores!", _
            MsgBoxStyle.Exclamation, _
            "Aviso!")

        ElseIf RichTextBox1Decimal.Text <> "" Then

            RichTextBox2Hex.Text = Hex(RichTextBox1Decimal.Text)

        ElseIf RichTextBox2Hex.Text <> "" Then

            RichTextBox1Decimal.Text = CInt("&H" & RichTextBox2Hex.Text)

        End If


        Dim ParaInverterEmPares As String

        ParaInverterEmPares = RichTextBox2Hex.Text

        
        'RichTextBox3HexInvertido.Text = StrReverse(ParaInverterEmPares)
        RichTextBox3HexInvertido.Text = Mid(ParaInverterEmPares, 2)


        


    End Sub
End Class
Link to comment
Share on other sites

Estava a substituir uma parte do código acima usando a função Format mas, se

eu escrever "354" na RichTextBoxDecimal a mesma não exibe os números "00000162"

na RichTextBoxHex. Alguém me sabe dizer o porquê?

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' Se eu escrevo "354" na RichTextBox1Decimal, 
        ' então, tenho de obter "62010000" na RichTextBox3HexInvertido...

        If RichTextBox1Decimal.Text = "" And RichTextBox2Hex.Text = "" Then

            MsgBox("Tem de introduzir valores!", _
            MsgBoxStyle.Exclamation, _
            "Aviso!")

        ElseIf RichTextBox1Decimal.Text <> "" Then

            'RichTextBox2Hex.Text = Hex(RichTextBox1Decimal.Text)
            RichTextBox2Hex.Text = Format(Hex(RichTextBox1Decimal.Text), "00000000")
           
        ElseIf RichTextBox2Hex.Text <> "" Then

            RichTextBox1Decimal.Text = CInt("&H" & RichTextBox2Hex.Text)

        End If


        Dim ParaInverterEmPares As String

        ParaInverterEmPares = RichTextBox2Hex.Text

        
        'RichTextBox3HexInvertido.Text = StrReverse(ParaInverterEmPares)
        RichTextBox3HexInvertido.Text = Mid(ParaInverterEmPares, 2)



    End Sub
End Class
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.