Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Simple easy TEXT to number

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBWin Simple easy TEXT to number

    Telephone numbers are frequently given as text as we all know so that it can be remembered easily. The problem is having to look up the numbers before dialing. If your sight is getting worse for small letters/numbers this can be
    irritating. Here is a simple program that translates text to numbers and displays in a large font. I have found it to be handy.
    It formats the number (U.S.) if the length of the number trimmed for spaces is 7, 10, or 11 numbers.
    Code:
    #COMPILE EXE
    '#DIM ALL
    #INCLUDE "win32api.inc"
    GLOBAL hDlg AS DWORD, UserEntry AS STRING, DlgResult AS LONG, doneit%
    GLOBAL Telenumber$
    CALLBACK FUNCTION MainPageCallback
      STATIC newnum$
      'SELECT CASE CB.MSG 'pbwin9 and above
      SELECT CASE CBMSG
        
        CASE %WM_INITDIALOG
          newnum$=""
        CASE %WM_COMMAND
          'SELECT CASE CB.CTL 'pbwin9 and above
          SELECT CASE CBCTL
             CASE 201
                CONTROL GET TEXT hDlg,201 TO UserEntry
                Telenumber$=UserEntry
            CASE 301
              FOR kk&=1 TO LEN(Telenumber$)
                char$=UCASE$(MID$(Telenumber$,kk&,1))
                SELECT CASE char$
                  CASE "A","B","C"
                    num$="2"
                  CASE "D","E","F"
                    num$="3"
                  CASE "G","H","I"
                    num$="4"
                  CASE "J","K","L"
                    num$="5"
                  CASE "M","N","O"
                    num$="6"
                  CASE "P","Q","R","S"
                    num$="7"
                  CASE "T","U","V"
                    num$="8"
                  CASE "W","X","Y"
                    num$="9"
                  CASE "1","2","3","4","5","6","7","8","9","0"
                    num$=char$ 'MID$(Telenumber$,kk&,1)
                  CASE ELSE
                    num$=" "
                END SELECT
                IF num$<>"" THEN
                  newnum$=newnum$+num$
                END IF
                num$=""
              NEXT
              savenum$=newnum$
              x$=REMOVE$(newnum$," ")
              IF LEN(x$)=11 THEN
                newnum$=LEFT$(x$,1)+" ("+MID$(x$,2,3)+") "+MID$(x$,5,3)+"-"+MID$(x$,8)
              ELSEIF LEN(x$)=10 THEN
                newnum$="("+MID$(x$,1,3)+") "+MID$(x$,4,3)+"-"+MID$(x$,7)
              ELSEIF LEN(x$)=7 THEN
                newnum$=MID$(x$,1,3)+"-"+MID$(x$,4)
              ELSE
                newnum$=savenum$
              END IF
    '          if doneit%=0 then
    '             msgbox "newnum$= "+newnum$
    '             doneit%=1
    '          end if
             CONTROL SET TEXT hDlg,151,TRIM$(newnum$)
    
            CASE 302
              DIALOG END hDlg,0
            CASE 303
              newnum$=""
              CONTROL SET TEXT hDlg,151,""
              CONTROL SET TEXT hDlg,201,""
          END SELECT
        END SELECT
    END FUNCTION
    FUNCTION PBMAIN () AS LONG
        LOCAL lf AS LOGFONT, hFontBigttf AS LONG
        GetObject GetStockObject(%ANSI_VAR_FONT), SIZEOF(lf), BYVAL VARPTR(lf)
        lf.lfHeight = 32'*yoffset! '48 '-14
        lf.lfWidth  = 16'*xoffset! '24*xoffset!
        lf.lfWeight = %FW_BOLD
        lf.lfItalic = 0 '1
        lf.lfFaceName =  "Times NEW Roman" 'SF Square Root" 'PXPED Light"'"Times NEW Roman"' Bold Italic" 'Courier New" 'Arial" 'MS Sans Serif" '"MS UI Gothic" '"MS Linedraw" '"Courier New"'Arial" '
        hFontBigttf = CreateFontIndirect(lf)
    
            DIALOG NEW %Null, "Translate Phone Numbers",,, 260,100, %WS_POPUP OR _
             %WS_BORDER OR %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_CAPTION OR _
             %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS _
             OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
             %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_WINDOWEDGE OR _
             %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
             %WS_EX_RIGHTSCROLLBAR, TO hDlg
            CONTROL ADD LABEL,   hDlg,101,"Enter Telephone Number text ",5,10,150,12
            CONTROL ADD TEXTBOX, hDlg,201,"",                          155,10,100,12
            CONTROL ADD LABEL,   hDlg,151,"",                           25,25,200,24
            CONTROL SEND hDlg,151,%WM_SETFONT, hFontBigttf, %TRUE
    
            CONTROL ADD BUTTON,  hDlg,301,"OK",                         55,70,035,18
            CONTROL ADD BUTTON,  hDlg,302,"Cancel",                     95,70,035,18
            CONTROL ADD BUTTON,  hDlg,303,"Clear",                     135,70,035,18
            DIALOG SHOW MODAL hDlg CALL MainPageCallback TO DlgResult
    
    END FUNCTION
    Last edited by Fred Buffington; 31 Aug 2009, 12:28 PM.
    Client Writeup for the CPA

    buffs.proboards2.com

    Links Page
Working...
X