我想在VB SCRIPT中使用函数来计算数字命理

-1 algorithm vbscript function

我想要一个函数来计算数字命理.例如,如果我输入"XYZ",那么我的输出应该是3.

这是它变成3:

X = 24
Y = 25
Z = 26
Run Code Online (Sandbox Code Playgroud)

添加它变成75再次加起来12(7 + 5)再次加起来3(1 + 2).同样,无论我应该传递什么名字,我的输出应该是一位数的分数.

Hel*_*len 5

这个给你:

Function Numerology(Str)
  Dim sum, i, char

  ' Convert the string to upper case, so that 'X' = 'x'
  Str = UCase(Str)

  sum = 0
  ' For each character, ...
  For i = 1 To Len(Str)
    ' Check if it's a letter and raise an exception otherwise
    char = Mid(Str, i , 1)
    If char < "A" Or char > "Z" Then Err.Raise 5 ' Invalid procedure call or argument

    ' Add the letter's index number to the sum
    sum = sum + Asc(char) - 64
  Next

  ' Calculate the result using the digital root formula (http://en.wikipedia.org/wiki/Digital_root)
  Numerology = 1 + (sum - 1) Mod 9
End Function
Run Code Online (Sandbox Code Playgroud)