www.webdeveloper.com
Results 1 to 10 of 10

Thread: VB Convert numbers to letters

  1. #1
    Join Date
    Aug 2004
    Posts
    94

    Lightbulb VB Convert numbers to letters

    Hi guys,

    I am hoping this is really simple. Does anyone know how to use VB to convert a number to the corresponding letter in the alphabet i.e. the number 2 = B or 5 = E etc...

    It's been a while I know. I hope things are working out for you all.

    Cheers again.

    Dan
    Professional Web Management
    Content Management Specialists

  2. #2
    Join Date
    Nov 2002
    Posts
    4,473
    Not sure if this is "simple" enough...
    Code:
    abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    function convert(n)
      convert = Mid(abc, n, 1)
    end function
    ...
    response.write(convert(3))

  3. #3
    Join Date
    Aug 2004
    Posts
    94

    Question

    Hi Gil,

    Thank you very much. You are right, it was easy. Now is the hard part...

    What if I wanted to convert the same but using a number such as: 221168 in the same letters which should read BBAAFH? I have tried using the split facility but cannot get that to work properly...

    Thanks again for your time Gil.

    Dan
    Professional Web Management
    Content Management Specialists

  4. #4
    Join Date
    Nov 2002
    Posts
    4,473
    Code:
    st = Cstr(221168)
    rslt = ""
    for i = 0 to Len(st)
      rslt = rslt & convert(Mid(st, i, 1))
    next
    response.write(rslt)

  5. #5
    Join Date
    Aug 2004
    Posts
    94

    Question

    Hi Gil,

    Thanks again for the update. So this is the code I hace combined:

    <%
    abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    function convert(n)
    convert = Mid(abc, n, 1)
    end function

    st = Cstr(221168)
    rslt = ""
    for i = 0 to Len(st)
    rslt = rslt & convert(Mid(st, i, 1))
    next
    response.write(rslt)
    %>


    The error reponse I receive is:

    Microsoft VBScript runtime error '800a0005'

    Invalid procedure call or argument: 'Mid'

    /Test.asp, line 10


    What have I done wrong?

    Dan
    Professional Web Management
    Content Management Specialists

  6. #6
    Join Date
    Nov 2002
    Posts
    4,473
    for i = 0 to Len(st)
    My bad
    Code:
    for i = 1 to Len(st)

  7. #7
    Join Date
    Aug 2004
    Posts
    94

    Smile

    Gil,

    You are a star! Thank you very much for all of your effort and time. That works perfectly now.

    Many thanks again

    Dan
    Professional Web Management
    Content Management Specialists

  8. #8
    Join Date
    May 2010
    Posts
    1

    MAS 90 VBS convert number to letters

    Along the same lines as the thread I have a need to create a script to convert a customer order total to letters using same convention 1=A, 2=B, 3=C, 4=D, 5=E, 6=F, 7=G, 8=H, 9=I 0=J.

    i.e. field SO_NetOrderAmount = 1920.55
    script will convert this number to AIBJEE

  9. #9
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    I'm not sure if there is a numberformat that will remove the decimal..

    this would do it


    field SO_NetOrderAmount = 1920.55
    field SO_NetOrderAmount = replace(field SO_NetOrderAmount,".","")

  10. #10
    Join Date
    Oct 2012
    Posts
    1
    what if you have multiple values assigned to one number like: 2 can equal A,B,C. (like a phone)

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles