其他分享
首页 > 其他分享> > VBA 左移和右移

VBA 左移和右移

作者:互联网

'左移函数

Function LShift(Value, Shift)

    Set sc = CreateObject("MSScriptControl.ScriptControl")

    sc.Language = "JScript"

    LShift = sc.Eval(Value & "<<" & Shift)

End Function

 

'右移函数

 

Function RShift(Value, Shift)

    Set sc = CreateObject("MSScriptControl.ScriptControl")

    sc.Language = "JScript"

    RShift = sc.Eval(Value & ">>" & Shift)

End Function

 

工作中遇到的加密算法示例:

Sub MyModelID()

 

    Dim i As Integer

    Dim rs  As Long

    Dim n_brandid  As Long

    Dim n_modelid  As Long

   

    For i = 2 To UsedRange.Rows.Count

        rs = Cells(i, 2) Mod LShift(1, 7) 'Brandid

        n_brandid = rs + LShift(rs, 7)

        n_modelid = Cells(i, 1) Xor n_brandid

        n_modelid = LShift(n_modelid, 7) + rs

        Cells(i, 6) = n_modelid

       

        If IsNumeric(Cells(i, 3)) And IsEmpty(Cells(i, 3)) <> True Then

            Cells(i, 8) = Cells(i, 3) * 2 / 60 + 2

            Cells(i, 9) = Cells(i, 4) / 60

            Cells(i, 10) = Cells(i, 5) / 60

        Else

            Cells(i, 8) = 8888

            Cells(i, 9) = 8888

            Cells(i, 10) = 8888

        End If

           

       

       ' Debug.Print Cells(i, 6)

    Next

   

    MsgBox "完成!"

   

End Sub

 

标签:右移,VBA,End,rs,Cells,左移,LShift,sc,modelid
来源: https://www.cnblogs.com/april6/p/14763004.html