如何编辑以下VBA代码?

huangapple go评论98阅读模式
英文:

How to edit the following VBA code?

问题

我在另一个论坛上请求修改一个VBA代码,一个名叫“Harun24hr”的人帮助我编写了一个代码(非常感谢他),但我没有成功完成第二个代码。

这段代码用于计算银行账号的密钥,但我想修改它,使其仅考虑从右边数的10个数字来计算相应的密钥。

例如,如果数字是:6465981,代码将考虑全部数字,因为它有7位数。如果数字是007999990006465981,它将取0006465981来计算密钥。

以下是代码:

Public Function RIP(Cle_RIP As String) As String

If Cle_RIP = "" Then
   Cle_RIP = 0
End If

RIP = Cle_RIP * 100
RIP = RIP - 97 * Int(RIP / 97)
RIP = RIP + 85

If RIP < 97 Then
   RIP = RIP + 97
Else
   RIP = RIP
End If

RIP = RIP - 97
RIP = 97 - RIP

If RIP < 10 Then
   RIP = "0" & RIP
Else
   RIP = RIP
End If
End Function

希望这对你有所帮助。

英文:

I have asked on another forum for a modification of a VBA code, a guy named « Harun24hr » helped me with one code (thanks a lot to him), but I didn’t manage to do with the second one.

The code calculates the key of a bank account number, but I want to modify it so that the code would take 10 numbers from the right to calculate the corresponding key.

For example, if the number is : 6465981, the code will take it all into consideration since it’s 7 numbers long. If the number is 007999990006465981, it will take 0006465981 to calculate the key.

The code is:

Public Function RIP(Cle_RIP As String) As String

If Cle_RIP = &quot;&quot; Then
   Cle_RIP = 0
End If

RIP = Cle_RIP * 100
RIP = RIP - 97 * Int(RIP / 97)
RIP = RIP + 85

If RIP &lt; 97 Then
   RIP = RIP + 97
Else
   RIP = RIP
End If

RIP = RIP - 97
RIP = 97 - RIP

If RIP &lt; 10 Then
   RIP = &quot;0&quot; &amp; RIP
Else
   RIP = RIP
End If
End Function

答案1

得分: 3

你可以使用Right函数来获取字符串的最右边部分,所以...

Public Function RIP(Cle_RIP As String) As String

    Cle_RIP = Right(Cle_RIP, 10)

    If Cle_RIP = "" Then
       Cle_RIP = 0
    End If

'.....您代码的其余部分
英文:

You can use the Right function to get the right-most part of a string, so...

Public Function RIP(Cle_RIP As String) As String

    Cle_RIP = Right(Cle_RIP, 10)

    If Cle_RIP = &quot;&quot; Then
       Cle_RIP = 0
    End If

&#39;.....rest of your code

huangapple
  • 本文由 发表于 2023年8月10日 20:30:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76939392.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定