我想一个函数在VB脚本来计算命理 [英] I want a function in VB SCRIPT to calculate numerology

查看:84
本文介绍了我想一个函数在VB脚本来计算命理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个函数来计算numerology.For例如,如果我输入XYZ,那么我的输出应为3。

I want a function to calculate numerology.For example if i enter "XYZ" then my output should be 3 .

下面是如何变成了3:

X = 24
Y = 25
Z = 26

上增加它成为75,它再次加起来12(7 + 5),再次加起来3(1 + 2)。同样什么名字,我要过去,我的输出应该是个位​​数的分数。

on adding it becomes 75 which again adds up to 12 (7+5) which again adds up to 3(1+2) . Similarly whatever names i should pass,my output should be a single digit score.

推荐答案

在这里,您是:

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

这篇关于我想一个函数在VB脚本来计算命理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆