• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

swapping bytes in visual basic?

KLin

Lifer
Anyone have any sample code on how to do this? Specifically when dealing with a string value. I'm reading a string value(bin and lot values) from an embedded system(in a weight scale).

Of course the value comes across garbled because the bytes aren't in the right order. I tried to find some sample code in vb to try and read in a string, swap the bytes, then output it correctly. I wasn't able to find anything that I could get to work.

http://pics.bbzzdd.com/users/klin/bytes.JPG

Bin value should be 12345. Lot should be H12345. Interesting issue when I switch windows, I see those tab like characters in the record. I just have it in an access form at the moment.

Thanks!.
 
Originally posted by: KLin
I'm not referring to string manipulation functions.

http://en.wikipedia.org/wiki/Endianness

That's what I'm referring to with my question. 🙂

A single character is a byte long. With the Endian problems the the bytes are generally not in the right order, so string manipulation really is what you want to deal with.

[edit]Removed because I now see what I was missing earlier[/edit]
 
Originally posted by: Cogman
Originally posted by: KLin
I'm not referring to string manipulation functions.

http://en.wikipedia.org/wiki/Endianness

That's what I'm referring to with my question. 🙂

A single character is a byte long. With the Endian problems the the bytes are generally not in the right order, so string manipulation really is what you want to deal with.

[edit]Removed because I now see what I was missing earlier[/edit]

I finally figured out how to fix the problem after your reply. I was initially reading in the value as a string from the device. I decided to change it to read in each byte and build the string on the fly using the chr() function. Thanks! 🙂
 
Originally posted by: KLin
Originally posted by: Cogman
Originally posted by: KLin
I'm not referring to string manipulation functions.

http://en.wikipedia.org/wiki/Endianness

That's what I'm referring to with my question. 🙂

A single character is a byte long. With the Endian problems the the bytes are generally not in the right order, so string manipulation really is what you want to deal with.

[edit]Removed because I now see what I was missing earlier[/edit]

I finally figured out how to fix the problem after your reply. I was initially reading in the value as a string from the device. I decided to change it to read in each byte and build the string on the fly using the chr() function. Thanks! 🙂

🙂 Np. I guess that works as well as anything else. I'm not a fan of VB strings. I like my abilities to manipulate strings in c++.

for (int i = 0; i < string.size(); i += 2)
{
swap(string[ i ], string[i + 1]);
}

and done :0. The VB code is much messier.
 
Private Sub cmdGetData_Click()
Dim i As Long, strBin As String, strLot As String
ASMBTCP0.MemStart = "40707"
ASMBTCP0.MemQty = 10
ASMBTCP0.SyncRefresh
For i = 0 To 9
If ASMBTCP0.GetDataByteM(i) <> 0 Then
strBin = strBin & Chr(ASMBTCP0.GetDataByteM(i))
End If
Next i
Bin = Trim(strBin)
ASMBTCP0.MemStart = "40717"
ASMBTCP0.MemQty = 10
ASMBTCP0.SyncRefresh
For i = 0 To 9
If ASMBTCP0.GetDataByteM(i) <> 0 Then
strLot = strLot & Chr(ASMBTCP0.GetDataByteM(i))
End If
Next i
Lot = Trim(strLot)
Me.Repaint
End Sub

That's my code. ASMBTCP0 is just an activex control object added to a form to allow communication with the scale HMI. 🙂
 
Kind of glad I pasted that code. Access just crashed on me and I hadn't saved for a long time. 😛
 
Originally posted by: Cogman
Originally posted by: KLin
Originally posted by: Cogman
Originally posted by: KLin
I'm not referring to string manipulation functions.

http://en.wikipedia.org/wiki/Endianness

That's what I'm referring to with my question. 🙂

A single character is a byte long. With the Endian problems the the bytes are generally not in the right order, so string manipulation really is what you want to deal with.

[edit]Removed because I now see what I was missing earlier[/edit]

I finally figured out how to fix the problem after your reply. I was initially reading in the value as a string from the device. I decided to change it to read in each byte and build the string on the fly using the chr() function. Thanks! 🙂

🙂 Np. I guess that works as well as anything else. I'm not a fan of VB strings. I like my abilities to manipulate strings in c++.

for (int i = 0; i < string.size(); i += 2)
{
swap(string[ i ], string[i + 1]);
}

and done :0. The VB code is much messier.

wouldn't a VB Replace function work

 
Back
Top