英文:
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 = "" 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
答案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 = "" Then
Cle_RIP = 0
End If
'.....rest of your code
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论