Joca Posted April 27, 2008 at 02:54 PM Report Share #181682 Posted April 27, 2008 at 02:54 PM 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 More sharing options...
Joca Posted April 29, 2008 at 09:38 PM Author Report Share #182455 Posted April 29, 2008 at 09:38 PM 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now