Algorithm for adding up value of a string?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dixie

    Algorithm for adding up value of a string?

    If I had a table that could give a value to each letter in the alphabet, say
    from 1 for A to 26 for Z, would there be a simple way of adding up the total
    numerical value for a string of letters. Even better, could the entire
    thing be done in code with no table at all - assuming a simple straight
    numbering from 1 to 26?

    dixie


  • PC Datasheet

    #2
    Re: Algorithm for adding up value of a string?

    Letters in the alphabet have a built in valus called the Ascii value. A =
    65, Z = 90, a = 97 and z = 122.
    You can use the ASC function to retrunn the value of letters. From the Help
    file:
    This example uses the Asc function to return a character code corresponding
    to the first letter in the string.

    Dim MyNumber
    MyNumber = Asc("A") ' Returns 65.
    MyNumber = Asc("a") ' Returns 97.
    MyNumber = Asc("Apple") ' Returns 65.


    --
    PC Datasheet
    Your Resource For Help With Access, Excel And Word Applications
    resource@pcdata sheet.com



    "dixie" <dixie@dogmail. com> wrote in message
    news:4197c756$1 @duster.adelaid e.on.net...[color=blue]
    > If I had a table that could give a value to each letter in the alphabet,[/color]
    say[color=blue]
    > from 1 for A to 26 for Z, would there be a simple way of adding up the[/color]
    total[color=blue]
    > numerical value for a string of letters. Even better, could the entire
    > thing be done in code with no table at all - assuming a simple straight
    > numbering from 1 to 26?
    >
    > dixie
    >
    >[/color]


    Comment

    • Bas Cost Budde

      #3
      Re: Algorithm for adding up value of a string?

      dixie wrote:[color=blue]
      > If I had a table that could give a value to each letter in the alphabet, say
      > from 1 for A to 26 for Z, would there be a simple way of adding up the total
      > numerical value for a string of letters. Even better, could the entire
      > thing be done in code with no table at all - assuming a simple straight
      > numbering from 1 to 26?[/color]

      Yes! You can calculate the 'value' of a letter by taking its Asc(),
      maybe AND out bit 5 (for 32 to distinguish between upper and lower caps)
      and subtracting 64

      air code:

      function numerological(s tringin as string) as long
      dim res as long
      for i=1 to len(stringin)
      res=res + asc(mid(stringi n,i,1))-asc("a")+1
      next
      numerological=r es
      end function

      Comment

      • dixie

        #4
        Re: Algorithm for adding up value of a string?

        I put that into a module, then, how do I make it run on a certain string
        that was say in table or a query?

        dixie

        "Bas Cost Budde" <b.costbudde@he uvelqop.nl> wrote in message
        news:cn8ic6$ker $1@news2.solcon .nl...[color=blue]
        > dixie wrote:[color=green]
        >> If I had a table that could give a value to each letter in the alphabet,
        >> say from 1 for A to 26 for Z, would there be a simple way of adding up
        >> the total numerical value for a string of letters. Even better, could
        >> the entire thing be done in code with no table at all - assuming a simple
        >> straight numbering from 1 to 26?[/color]
        >
        > Yes! You can calculate the 'value' of a letter by taking its Asc(), maybe
        > AND out bit 5 (for 32 to distinguish between upper and lower caps) and
        > subtracting 64
        >
        > air code:
        >
        > function numerological(s tringin as string) as long
        > dim res as long
        > for i=1 to len(stringin)
        > res=res + asc(mid(stringi n,i,1))-asc("a")+1
        > next
        > numerological=r es
        > end function[/color]


        Comment

        • PC Datasheet

          #5
          Re: Algorithm for adding up value of a string?

          You have to write code in an event somewhere like the click event of a
          button. The code is:

          Dim ValueOfString As Long
          ValueOfString = Numerological(N ameOfYourString )

          Or if you want to use it in a query, put the following expression in a blank
          field in a query:
          ValueOfString:N umerological([NameOfYourStrin gField])

          Note: This query will probably take a little while to run!


          --
          PC Datasheet
          Your Resource For Help With Access, Excel And Word Applications
          resource@pcdata sheet.com


          "dixie" <dixie@dogmail. com> wrote in message
          news:4197f21b$1 @duster.adelaid e.on.net...[color=blue]
          > I put that into a module, then, how do I make it run on a certain string
          > that was say in table or a query?
          >
          > dixie
          >
          > "Bas Cost Budde" <b.costbudde@he uvelqop.nl> wrote in message
          > news:cn8ic6$ker $1@news2.solcon .nl...[color=green]
          > > dixie wrote:[color=darkred]
          > >> If I had a table that could give a value to each letter in the[/color][/color][/color]
          alphabet,[color=blue][color=green][color=darkred]
          > >> say from 1 for A to 26 for Z, would there be a simple way of adding up
          > >> the total numerical value for a string of letters. Even better, could
          > >> the entire thing be done in code with no table at all - assuming a[/color][/color][/color]
          simple[color=blue][color=green][color=darkred]
          > >> straight numbering from 1 to 26?[/color]
          > >
          > > Yes! You can calculate the 'value' of a letter by taking its Asc(),[/color][/color]
          maybe[color=blue][color=green]
          > > AND out bit 5 (for 32 to distinguish between upper and lower caps) and
          > > subtracting 64
          > >
          > > air code:
          > >
          > > function numerological(s tringin as string) as long
          > > dim res as long
          > > for i=1 to len(stringin)
          > > res=res + asc(mid(stringi n,i,1))-asc("a")+1
          > > next
          > > numerological=r es
          > > end function[/color]
          >
          >[/color]


          Comment

          Working...