Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody,
I have a variable that contain several bytes. A measure is compose by 3 bytes. I need to recover all the measures that are coded every 3 bytes. How i can do that?
VB
Dim converter As New Systeme.Data.Records.RecordsDataToRecordsCollectionConverter(Monitoring)

Dim recordsCollection1 As Systeme.Devices.Records.IRecordsCollection = converter.convert(Data1)
 
For Each record As Systeme.IRecord In recordsCollection1.recordsList

   If record.recordType = Systeme.Interfaces.Devices.Records.RecordType.TrackMeasure Then

      Dim recordMeasure As Systeme.Interfaces.Devices.SpyRf.Records = TryCast(record, Systeme.Interfaces.Records)

   End If
End For

All information is in Data1. The information is in Bytes. I need to take every 3 bytes to have 1 mesure. Before i need to convert the bytes to string or double or Int.
Does any can help me?
Thans
Posted
Updated 6-Sep-13 2:17am
v2
Comments
[no name] 6-Sep-13 8:25am    
So basically, you do not know how to iterate through an array?
alonetmr 6-Sep-13 8:28am    
Yes, i have not idea how many times i need to iterate my array Data1.
But how i can take 3 bytes in each iteration?

1 solution

Ok, so Data1 is a byte array? How about this:

VB
Dim ms As New MemoryStream(Data1)
Dim buffer(2) As Byte

For count As Integer = 0 to (Data1.Length / 3) -1 
   ms.Read(buffer, 0, 3)
Next


The memorystream will pull 3 bytes off and fill buffer with them until all the bytes in Data1 have been read.

- Pete
 
Share this answer
 
Comments
Richard MacCutchan 7-Sep-13 5:48am    
I was going to "correct" your Dim statement, but then something went ping in my brain, so I checked with MSDN. I wonder what the designers were smoking when they decided that Dim buffer(2) As Byte means allocate a 3-byte buffer?
pdoxtader 7-Sep-13 8:41am    
Lol. Yeah, they made the array size assignment value zero based. I have no idea why they would do that, and I've always thought it was stupid and un-intuitive also.

And then Microsoft hired me.

One of the first things that I noticed working for this company was that the people who work there are the smartest, the hardest working, and the nicest people I've ever been lucky enough to work with. Also, the company makes them feel appreciated, and they are treated very well. They come and go when they like (I mean your boss is not watching the clock, and people tend to show up when they want, stay as long as they need to, and take time as they need it and never stress about it. The cool thing about that is that people seem to work harder, like their job more, and stay later.). More interesting is that I work in product testing, so I get to see how manual testing is done, bugs are opened and resolved, and be a part of one of the automated testing teams... and I can tell you that if it's been in the product this long, there's a good reason and it's by design.

I can't imagine what it is... lol. Maybe I'll ask one of the guys on that team, but I'm absolutely sure that this is the case... and when I ask them, and they explain it, I'll have an "Ohhhhh" moment.

- Pete
Richard MacCutchan 7-Sep-13 8:51am    
That's good to know, considering all the bad press Microsoft get; not that I'm entirely sure why.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900