Is there any HexBox Control or type of way to view a long (2mb) .bin file as USHORT with some control that shows the addresses and everything, that allows editing and saving the modified file?
File shown as example is WINOLS.
What would be the point of that? Looking at a byte stream as a series of UShorts is not the same thing a viewing it in hexadecimal. The hexadecimal view tells you what every single byte is. Looking at the stream as a series of UShorts really doesn't make that much sense. Like how should the bytes be interpreted? Little endian? Big endian? What happens to the left over byte if the byte stream's length is not a multiple of 2? This complicates things in my opinion.
C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter
There's just no reason to use garbage like InputBox. - jmcilhinney
The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber
LittleEndian. Bytes stream is always multiple of 2 from every processor memory ever made.
As you can see from the example, if i view the dump from the processor as 8bit nothing makes sense, it's just rubbish, but when I view it as Ushort(16bit) then I can see all the values as they should be.
The files are from 256kb to 3mb max in size and I need to view them somehow, I found a method to read the file as ushort and copy it to a richtextbox or tb but it takes 7min to process a 1mb file...
Oh so what you're actually saying is that your byte stream is simply an array of UShorts. Well this is a very specific format. Most likely you're going to have to roll your own editor for this.
C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter
There's just no reason to use garbage like InputBox. - jmcilhinney
The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber
Can this code be converted so that it reads as ushort instead of byte?
Code:
'name = full location to file
'rtb = richtextbox
Dim buff(1000000) As Byte
Using fs = New FileStream(name, FileMode.Open)
Using br = New BinaryReader(fs)
While True
Dim text = String.Empty
buff = br.ReadBytes(1000000)
Await Task.Run(Sub() text = String.Join(" ", buff.
Select(Function(b) b.ToString("X2")))).
ConfigureAwait(True)
rtb.AppendText(text)
If buff.Length < 1000000 Then
Exit While
End If
End While
End Using
End Using
Like I said, you're probably going to have to design this Control yourself. To be clear, you want to be able to edit this array of UShorts using some kind of GUI, right?
C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter
There's just no reason to use garbage like InputBox. - jmcilhinney
The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber
If possible yes. But if i find a way to edit that souce that I've posted to read ushort I will figure everything out without a problem.. It works without a problem reads a 4mb file and appends text in 0.5 sec ... if it could read it as ushort it would be the solution to all my problems..
Can this code be converted so that it reads as ushort instead of byte?
Code:
'name = full location to file
'rtb = richtextbox
Dim buff(1000000) As Byte
Using fs = New FileStream(name, FileMode.Open)
Using br = New BinaryReader(fs)
While True
Dim text = String.Empty
buff = br.ReadBytes(1000000)
Await Task.Run(Sub() text = String.Join(" ", buff.
Select(Function(b) b.ToString("X2")))).
ConfigureAwait(True)
rtb.AppendText(text)
If buff.Length < 1000000 Then
Exit While
End If
End While
End Using
End Using
Something like this:-
Code:
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'rtb = richtextbox
Dim name As String = "d:\ANSI-Unicode-2.png" 'Your file name goes here...
Dim sb As New StringBuilder
rtb.Text = "Processing file. Please wait....."
rtb.ReadOnly = True
Await Task.Run(Sub()
Using fs = New FileStream(name, FileMode.Open)
Using br = New BinaryReader(fs)
Do Until fs.Position = fs.Length
sb.Append(br.ReadUInt16.ToString("X4"))
sb.Append(" ")
Loop
End Using
End Using
End Sub)
rtb.Text = sb.ToString
rtb.ReadOnly = False
End Sub
C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter
There's just no reason to use garbage like InputBox. - jmcilhinney
The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber
It seems that isn't ushort?
This code gives me the values that I need:
Code:
Dim bin8() As Byte = System.IO.File.ReadAllBytes("C:\Users\PCX\Desktop\LONG_TEST.bin")
Dim bin16(UBound(bin8) \ 2) As UInt16
Try
For i As UInteger = 0 To UBound(bin16)
bin16(i) = bin8(2 * i) + 256 * bin8(2 * i + 1)
Next
Catch ex As IndexOutOfRangeException
bin16(UBound(bin16)) = bin8(UBound(bin8))
End Try
Last edited by ProElectronicZR; Sep 16th, 2021 at 04:55 PM.
Niya's code was creating hex string representations of the 16-bit integers, which is what you were talking about, i.e. an editor representation.
Your code is just getting the 16-bit integers values themselves, so two different requirements.
If you just wanted to convert the file into UInt16 or UShort, we already mentioned how to do that in your other thread.
The code given before would be
Code:
Dim bin8() As Byte = System.IO.File.ReadAllBytes("C:\Users\PCX\Desktop\LONG_TEST.bin")
Dim bin16((bin8.ubound \ 2)) As UInt16
Buffer.BlockCopy(bin8,0,bin16,0,bin8.Length)
No need to loop, catch an exception or multiply and add pairs of bytes together, as the way you're multiplying and combining indicates the values are little endian, so just copy the bytes from the bin8 array to the bin16 array will be the correct byte order.
You can try both way and compare the results to see that it works.
Now you need to decide what you want to do with those values. Niya was showing the conversion from value to hex representation which you would need to present the number to the user to be edited.
Your example editor shows the values in decimal, not hex, and perhaps that is what you want, in which case Niya's code isn't applicable, but your requirements of how you wanted the numbers presented wasn't clear. Perhaps you would like both as options.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
Can that code you wrote be adopted to @Niya's code? YES! It needs to show 16bit DECIMAL values. No I only need to see them in 16bit decimal, as you and others helped me with the code for replacing said values.
If you want Niya's code to display decimal padded to 5 characters as the editor does, then change the one sb.append to pad the number with 0's and not convert to hex (no "X4")
But note that the thread title does mention HexBox Control which implies hex, not decimal output.
The way I read the file could be adapted to Niya's code, but since you need to loop through the values to write them to the textbox, it probably doesn't really save that much, as an example.
But in the long run, I think if you really want to be able to make an editor, then you probably do want to read the file into a local array that can be maintained, modified and written back out. The other option is to have to scan the string from the textbox to convert the string back into an array of bytes to write to the file.
Last edited by passel; Sep 16th, 2021 at 05:26 PM.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
Went ahead an merged my read, with Niya's string creation, as an example...
Code:
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'rtb = richtextbox
Dim bin8() As Byte = System.IO.File.ReadAllBytes("C:\Users\PCX\Desktop\LONG_TEST.bin")
Dim bin16(UBound(bin8) \ 2) As UInt16
Buffer.BlockCopy(bin8, 0, bin16, 0, bin8.Length)
Dim sb As New StringBuilder
rtb.Text = "Processing file. Please wait....."
rtb.ReadOnly = True
Await Task.Run(Sub()
For Each u16 As UInt16 In bin16
sb.Append(u16.ToString().PadLeft(5, "0"c))
sb.Append(" ")
Next
End Sub)
rtb.Text = sb.ToString
rtb.ReadOnly = False
End Sub
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
I guess the question there is why?
The code you provided in post #11 doesn't swap the bytes before joining them into a ushort. It may look like it does, but it doesn't.
Is it possible the editor shows the bytes in big endian order and you want to replicate that?
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
You can choose between 8bit decimal, 8bit hex, 16bit decimal, 16bit hex, 16bit(HiLo) and 16bit(LoHi). Some processor memories byte swap so the ushort needs to be byte swapped before-hand so that what I see is what it is. But in my case I only need the ushort variants swapped or not swapped.