+ Reply to Thread
Results 1 to 4 of 4

byte order reversal in spreadsheet

  1. #1
    CuriousMark
    Guest

    byte order reversal in spreadsheet

    I have a spreadsheet with a very long hex string containing data stored on a
    big endian computer (or is it little, doesn't matter it's reversed) and the
    byte order is reversed. I have a VBA sub that takes a string as input and
    returns a reverse byte ordered string as a result. That is simple and
    straightforward. Now the hard part, how do I call that sub in the
    spreadsheet as if it were a function? I find help information on how to use
    spreadsheet functions in VBA, but not the other way around. I should point
    out this is my first VBA usage (office 2003) that wasn't just a modification
    of a recorded macro. So I expect the answer will be basic and obvious (once
    you know it).
    Thanks in advance for your help,
    Mark

  2. #2
    Niek Otten
    Guest

    Re: byte order reversal in spreadsheet

    Hi Mark,

    Why not post the code of your Sub, so we can see how to transform that into
    a Function?

    --

    Kind Regards,

    Niek Otten

    Microsoft MVP - Excel

    "CuriousMark" <[email protected]> wrote in message
    news:[email protected]...
    >I have a spreadsheet with a very long hex string containing data stored on
    >a
    > big endian computer (or is it little, doesn't matter it's reversed) and
    > the
    > byte order is reversed. I have a VBA sub that takes a string as input and
    > returns a reverse byte ordered string as a result. That is simple and
    > straightforward. Now the hard part, how do I call that sub in the
    > spreadsheet as if it were a function? I find help information on how to
    > use
    > spreadsheet functions in VBA, but not the other way around. I should
    > point
    > out this is my first VBA usage (office 2003) that wasn't just a
    > modification
    > of a recorded macro. So I expect the answer will be basic and obvious
    > (once
    > you know it).
    > Thanks in advance for your help,
    > Mark




  3. #3
    Tom Ogilvy
    Guest

    Re: byte order reversal in spreadsheet

    In a general module in that workbook put in your code as a function
    (insert=>Module in the VBE)

    Public Function MyReverseString(rng as Range)
    Dim s as String
    s = rng(1).Value
    ' code to reverse s and place results in s
    MyReverseString = s
    End Function

    then in a cell put in

    =MyReverseString(A1)

    --
    Regards,
    Tom Ogilvy

    "CuriousMark" <[email protected]> wrote in message
    news:[email protected]...
    > I have a spreadsheet with a very long hex string containing data stored on

    a
    > big endian computer (or is it little, doesn't matter it's reversed) and

    the
    > byte order is reversed. I have a VBA sub that takes a string as input and
    > returns a reverse byte ordered string as a result. That is simple and
    > straightforward. Now the hard part, how do I call that sub in the
    > spreadsheet as if it were a function? I find help information on how to

    use
    > spreadsheet functions in VBA, but not the other way around. I should

    point
    > out this is my first VBA usage (office 2003) that wasn't just a

    modification
    > of a recorded macro. So I expect the answer will be basic and obvious

    (once
    > you know it).
    > Thanks in advance for your help,
    > Mark




  4. #4
    CuriousMark
    Guest

    Re: byte order reversal in spreadsheet

    Niek, Tom
    Thank you.
    My code started out as a sub, but I started changing it to a function on my
    own, since I wanted a return variable behavior anyway. My current code is:

    Function ByteReverse(InputString As String)
    Dim i As Long
    Dim ByteStr, ResultStr As String
    ResultStr = ""
    For i = (Len(InputString) - 1) To 1 Step -2
    ByteStr = Mid(InputString, i, 2)
    ResultStr = ResultStr & ByteStr
    Next i

    ByteReverse = ResultStr

    End Function

    And seeing Tom's response I realized (slap hand on forehud and yell DUH)
    That what I have would already work as is, well sort of, I should use the
    range thing instead of just assuming string, which I will fix forthwith.

    Sure enough it just works. A VBA Function becomes a spreadsheet function
    without even needing to be told. If only I had found that in the help file!

    Again, thank you very much.

    Mark Evanetich

    "Tom Ogilvy" wrote:

    > In a general module in that workbook put in your code as a function
    > (insert=>Module in the VBE)
    >
    > Public Function MyReverseString(rng as Range)
    > Dim s as String
    > s = rng(1).Value
    > ' code to reverse s and place results in s
    > MyReverseString = s
    > End Function
    >
    > then in a cell put in
    >
    > =MyReverseString(A1)
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "CuriousMark" <[email protected]> wrote in message
    > news:[email protected]...
    > > I have a spreadsheet with a very long hex string containing data stored on

    > a
    > > big endian computer (or is it little, doesn't matter it's reversed) and

    > the
    > > byte order is reversed. I have a VBA sub that takes a string as input and
    > > returns a reverse byte ordered string as a result. That is simple and
    > > straightforward. Now the hard part, how do I call that sub in the
    > > spreadsheet as if it were a function? I find help information on how to

    > use
    > > spreadsheet functions in VBA, but not the other way around. I should

    > point
    > > out this is my first VBA usage (office 2003) that wasn't just a

    > modification
    > > of a recorded macro. So I expect the answer will be basic and obvious

    > (once
    > > you know it).
    > > Thanks in advance for your help,
    > > Mark

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1