We help IT Professionals succeed at work.

How to place the a string the big-endian order in Ms Access VBA

I need help to place the order of a string "864"into Big-endian before conversion to binary:

Private Sub Cmdendians_Click()
Dim strstrong As String, datastr As Byte
datastr = Len("864")
DecimalValue = datastr
BinaryValue = DecToBin(DecimalValue, 8)
Debug.Print DecToBin(DecimalValue, 8)
End Sub

Open in new window

Screen Shoot
Watch Question

Test your restores, not your backups...
Expert of the Year 2019
Top Expert 2016
A VB string should already be in big-endian by default, so as you take each byte one by one using say MID() you should have the proper order.

For example, this test:

Sub Test()
    s = "864"
    For i = 1 To Len(s)
        Debug.Print Mid(s, i, 1) & " = 0x" & Hex(Asc(Mid(s, i, 1)))
End Sub

Open in new window

Produces this result, as expected:

8 = 0x38
6 = 0x36
4 = 0x34

Open in new window

ste5anSenior Developer

There is no such thing for strings.

Endianess describes the order of bits. Most significant first or last. Normally it also means that we look at bytes ordered by that. Thus it makes only sense for numbers (word, dword, qword).

Thus what's your use-case?
Thank you Bill Prew for saving me again , you efforts are highly appreciated.