Question : vb.net - hex data

hello there,
I have this hex converter but I would like to make it work.. converted from C# im getting an error on Convert.ToString
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            textBox2.Clear()
            textBox1.Text = textBox1.Text.Replace(" ", "")
            textBox1.Text = textBox1.Text.Replace(vbLf & vbTab, "")
            textBox1.Text = textBox1.Text.Trim()
            Dim StrLen As Integer = textBox1.Text.Length
            Dim a As Integer = 0
            While a < StrLen
                Dim Char2Convert As String = textBox1.Text.Substring(a, 2)
                Dim n As Integer = Convert.ToInt32(Char2Convert, 16)
                Dim c As Char = ChrW(n)

                textBox2.Text = textBox2.Text + c.ToString()
                a = a + 2
            End While
        Catch ex As Exception
            MessageBox.Show("Conversion Error Occured : " & ex.Message, "Conversion Error")
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            textBox1.Clear()
            textBox2.Text = textBox2.Text.Replace(" ", "")
            textBox2.Text = textBox2.Text.Replace(vbLf & vbTab, "")
            textBox2.Text = textBox2.Text.Trim()
            Dim StrLen As Integer = textBox2.Text.Length
            Dim a As Integer = 0
            While a < StrLen
                Dim Char2Convert As String = textBox2.Text.Substring(a, 1)
                Dim c As Char = Char2Convert.ToCharArray(0, 1)(0)
                Dim n As String = Convert.ToString(c, 16)

                textBox1.Text = textBox1.Text + n & " "
                a = a + 1
            End While
        Catch ex As Exception
            MessageBox.Show("Conversion Error Occured : " & ex.Message, "Conversion Error")
        End Try
    End Sub
End Class

Answer : vb.net - hex data

I copy/paste your Hex Code into my Hex.txt and parse it using this method (see code).

I recreate the exact same data (except for the lower case generated from my hex viewer tool):

30818902818100b17d325a8a507d48dbdfcbe2e63649b00c0ecdc2405fa3b017f06ebfb92515234829773bb9ff2e8695cc6093bc137b7bd90ebddfe1d6ce45f97085ffc35ade5e3ebdec1204002566469507f81f6005930849f73114b9beddcf181c81b6d43a668c9b9a164eef6d6df23db62f4e72655725b69918c820bdb6f6954f2156cd74470203010001

Original hex:

30818902818100B17D325A8A507D48DBDFCBE2E63649B00C0ECDC2405FA3B017F06EBFB92515234829773BB9FF2E8695CC6093BC137B7BD90EBDDFE1D6CE45F97085FFC35ADE5E3EBDEC1204002566469507F81F6005930849F73114B9BEDDCF181C81B6D43A668C9B9A164EEF6D6DF23DB62F4E72655725B69918C820BDB6F6954F2156CD74470203010001
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
        Dim input As StreamReader
        Dim output As FileStream
        Dim hexLine As String

        input = File.OpenText("hex.txt")
        output = File.Create("text.txt")

        While Not input.EndOfStream
            hexLine = input.ReadLine()
            Dim StrLen As Integer = hexLine.Length
            Dim a As Integer = 0

            While a < StrLen
                output.WriteByte(Byte.Parse(hexLine.Substring(a, 2), System.Globalization.NumberStyles.HexNumber))
                a = a + 2
            End While

        End While

        input.Close()
        output.Close()
Random Solutions  
 
programming4us programming4us