Convert javascript to VBA RRS feed

  • Question

  • Hi all,

    I have to convert a javascript code to VBA. Almost of the code is OK but I can't find how to convert some particular function.

    For example, in this code, what are the equivalent for "|=" and for ">>>" in VBA ? For >> or << I use the functions "Bitlshift" or "BitRshift ", but for ">>>" and for "|=" I don't know.

    bin[i>>5] |= (str.charCodeAt(0)) << (24 - i%32)
    str += String.fromCharCode((bin[i>>5] >>> (24 - i%32)) & mask)

    Many thanks for any help,


    Friday, January 16, 2015 10:19 PM

All replies

  • I think this will do the >>>.

    Function ShiftRightZeroFill(value As Long, shift As Byte) As Long
        Dim i As Long
        i = value
        If shift > 0 Then
          ShiftRightZeroFill = Int(i / (2 ^ shift)) And &H7FFFFFFF
        End If
    End Function
    I don't even know what |= is in Javascript.  I don't see it in your example code.
    Friday, January 16, 2015 11:49 PM
  • Hi Mogulman52,

    thank you. The function is working fine.

    Concerning "|", it is in this line:

    bin[i>>5] |= (str.charCodeAt(0)) << (24 - i%32).

    I found this information but I don't find an existing function for this "Bitwise or assignment"

    Thank you for your help,


    Saturday, January 17, 2015 7:46 AM
  • The page says it is an OR operation so in VBA that operator is available.

    Function BitOr(val1 As Long, val2 As Long) As Long
      BitOr = val1 Or val2
    End Function

    • Edited by mogulman52 Sunday, January 18, 2015 9:29 PM
    Sunday, January 18, 2015 9:20 PM
  • Can u plz tell me , you convert java script code to  VBA.....?

    i have a illustrator java script code for finding centroid of a polygon.

    I want to use this code in corel draw as a vba macro.

    here is the JS script link - 

    Saturday, July 11, 2020 5:38 PM