Counting Letters

  • Thread starter Thread starter Sharkbyte
  • Start date Start date
S

Sharkbyte

Is there a way to 'count' the difference between 2 letters? Such as being
able to determine that if I begin with "M" then "K" and "O" are differences
of 2.

I know I could do it by associating each letter to a number, but I wanted to
save the time of doing the lookups, if at all possible.

TIA

Sharkbyte
 
Sharkbyte said:
Is there a way to 'count' the difference between 2 letters? Such as being
able to determine that if I begin with "M" then "K" and "O" are
differences
of 2.

I know I could do it by associating each letter to a number, but I wanted
to
save the time of doing the lookups, if at all possible.


?Asc("O") - Asc("M")
2

Note that this is case-sensitive:

?Asc("o") - Asc("m")
2
?Asc("O") - Asc("m")
-30

And it relies on the standard ASCII character mapping.
 
Sorry, no easy route on this one. There is nothing in code or function (which
I know of) that sets values for letters. You will need to define the value of
each letter to do the calculation.
--------------------------------------------

HTH

Don''t forget to rate the post if it was helpful!

Please reply to newsgroup only, so that others may benefit as well.
 
I should be able to use the UCase function to maintain consistency with
Ascii, correct?
 
Sharkbyte said:
I should be able to use the UCase function to maintain consistency with
Ascii, correct?

Sure. As in:

Function LetterDistance(FirstLetter As String, SecondLetter As String) _
As Integer

If FirstLetter = SecondLetter Then
LetterDistance = 0
ElseIf Len(FirstLetter) = 0 Then
LetterDistance = 32767 ' arbitrary
ElseIf Len(SecondLetter) = 0 Then
LetterDistance = -32767 ' equally arbitrary
Else
LetterDistance = _
Asc(UCase$(SecondLetter)) - Asc(UCase$(FirstLetter))
End If

End Function
 
Is there a way to 'count' the difference between 2 letters? Such as being
able to determine that if I begin with "M" then "K" and "O" are differences
of 2.

I know I could do it by associating each letter to a number, but I wanted to
save the time of doing the lookups, if at all possible.

TIA

Sharkbyte

You can use the Asc() function to return the ASCII value of the character.
Note that "a" and "A" have different values - 97 and 65 respectively. You may
want to use Asc(Ucase([fieldname])).
 
Maverick said:
Sorry, no easy route on this one. There is nothing in code or function
(which
I know of) that sets values for letters. You will need to define the value
of
each letter to do the calculation.
--------------------------------------------

HTH

Don''t forget to rate the post if it was helpful!

Please reply to newsgroup only, so that others may benefit as well.

Good thing most people don't read through the online interface and, thus,
can't "rate" this response, eh? If you'll read the responses, you'll find
that text characters are already assigned numbers... they are, in fact, just
a display interpretation of numbers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top