Code:
Sub Testit()
MsgBox prompt:=Weight("ZAC")
End Sub
' https://eileenslounge.com/viewtopic.php?f=30&t=38460&sid=4295ec4560088f42492ca29590271a87
Public Function Weight(S As String) As Long ' http://www.eileenslounge.com/viewtopic.php?p=297266#p297266
Dim Weights() As Variant ' Letters() As Variant,
Dim i As Long
' Letters = Array("A", "B", "C", ..., "Z")
' Weights = Array(1, 5, 3, ..., 2)
' A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
Let Weights() = Array(1, 5, 3, 1, 4, 3, 2, 1, 6, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 2) ' Watch : - : Weights() : : Variant/Variant(0 to 25) : Module1.Weight
For i = 1 To Len(S)
Let Weight = Weight + Weights(Asc(Mid(S, i, 1)) - 65)
Next i
End Function
Code:
Sub Testit()
Debug.Print Tab(4); "ASCII"; Tab(12); "Weight"
Debug.Print Tab(4); "Code"
Call Weight("ZAC")
Debug.Print
Call WeightLowerCase("zac")
End Sub
' https://eileenslounge.com/viewtopic.php?f=30&t=38460&sid=4295ec4560088f42492ca29590271a87
Public Function Weight(S As String) As Long ' http://www.eileenslounge.com/viewtopic.php?p=297266#p297266
Dim Weights() As Variant ' Letters() As Variant,
Dim i As Long
' A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
Let Weights() = Array(1, 5, 3, 1, 4, 3, 2, 1, 6, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 2) ' Watch : - : Weights() : : Variant/Variant(0 to 25) : Module1.Weight
For i = 1 To Len(S)
Let Weight = Weight + Weights(Asc(Mid(S, i, 1)) - 65)
Debug.Print Mid(S, i, 1); Tab(4); Asc(Mid(S, i, 1)); Tab(8); Asc(Mid(S, i, 1)) - 65; Tab(12); Weights(Asc(Mid(S, i, 1)) - 65)
Next i
End Function
Public Function WeightLowerCase(S As String) As Long ' http://www.eileenslounge.com/viewtopic.php?p=297266#p297266
Dim Weights() As Variant ' Letters() As Variant,
Dim i As Long
' a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
Let Weights() = Array(1, 5, 3, 1, 4, 3, 2, 1, 6, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 2) '
For i = 1 To Len(S)
Let WeightLowerCase = WeightLowerCase + Weights(Asc(Mid(S, i, 1)) - 97)
Debug.Print Mid(S, i, 1) & vbTab & Asc(Mid(S, i, 1)) & vbTab & Asc(Mid(S, i, 1)) - 97 & vbTab & Weights(Asc(Mid(S, i, 1)) - 97)
Next i
End Function
Bookmarks