首页 > 编程语言 > 详细

VBA 左移和右移

时间:2021-05-13 10:08:24      阅读:24      评论:0      收藏:0      [点我收藏+]

‘左移函数

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 左移和右移

原文:https://www.cnblogs.com/april6/p/14763004.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!