Results 1 to 8 of 8

Scan through a word and adding numbers of each letter

  1. #1
    sarcher is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2019
    Posts
    8

    Scan through a word and adding numbers of each letter

    So I have a table that has a corresponding number for each letter. I what the user to supply a text word - say 'MSACCESS'.


    I would like for the query to scan the word and add up the following for the letter number assignment table (tblTEXTNUM) example

    M = 1
    S = 2
    A = 3
    C = 4
    E = 5

    so M + S + A + C + C +E +S + S or 1+2+3+4+4+5+2+2

    equaling and returning the sum of 23 at the end


    TIA
    Stephen

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    20,375
    Create a VBA function that loops through the characters in the input (For/Next loop using the Len() function). For each letter, use a DLookup or recordset to get the associated number. Accumulate that in a variable and do what you want with it at the end.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    47,842
    A query alone won't accomplish this. Build a public VBA function that can be called from query or textbox. Like:

    Code:
    Function SumLetters(strL As String) As Integer
    Dim x As Integer, rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT Letter, Num FROM tblTextNum")
    For x = 1 To Len(strL)
        rs.FindFirst ("Letter='" & Mid(strL, x, 1) & "'")
        SumLetters = SumLetters + rs!Num
    Next
    End Function
    
    What is the reasoning for these letter/value assignments - why is M = 1, etc?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    20,375
    Quote Originally Posted by June7 View Post
    What is the reasoning for these letter/value assignments - why is M = 1, etc?
    It's exactly the type of homework I've had to do for my C# class.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    sarcher is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2019
    Posts
    8
    I just used it as random letter to number sequence -
    LTR NUM
    A 1
    B 2
    C 3
    D 4
    E 5
    F 6
    G 7
    H 8
    I 9
    J 1
    K 2
    L 3
    M 4
    N 5
    O 6
    P 7
    Q 8
    R 9
    S 1
    T 2
    U 3
    V 4
    W 5
    X 6
    Y 7
    Z 8

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    47,842
    Okay, so why are the Num values repeated?

    If this is just a school programming assignment and reason for number assignments is not important, ignore question.

    Does the code do what you want?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    sarcher is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2019
    Posts
    8
    Thanks every the Function worked Perfectly!

    Stephen

  8. #8
    sarcher is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2019
    Posts
    8
    Building a Numerlogy app

    whoo-whoo

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Capitalising First Letter of a Word
    By Alex Motilal in forum Reports
    Replies: 1
    Last Post: 04-25-2019, 01:00 AM
  2. sort field with numbers AND letter
    By dsmithe in forum Queries
    Replies: 12
    Last Post: 09-10-2018, 07:49 PM
  3. Numbers to a letter
    By snipe in forum Queries
    Replies: 3
    Last Post: 04-30-2015, 11:06 AM
  4. Replies: 5
    Last Post: 10-01-2014, 12:31 PM
  5. Replies: 2
    Last Post: 11-05-2013, 02:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums