Results 1 to 3 of 3

Thread: Writing on checks

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    46

    Writing on checks

    I am making a program that will print on checks. I have it so it will ask for the amount in a $12.50 format, and all the other info. But as I’m sure all of you know you also have to write it out like “Twelve dollars and 50/100*************” seems simple but I don’t know how to go about this.

  2. #2

    Thread Starter
    Member
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    46

    Re: Writing on checks

    i found the answer my self

    VB Code:
    1. '************ Code Start **********
    2.     'This code was originally written by Joe Foster.
    3.     'It is not to be altered or distributed,
    4.     'except as part of an application.
    5.     'You are free to use it in any application,
    6.     'provided the copyright notice is left unchanged.
    7.     '
    8.     'Code Courtesy of
    9.     'Joe Foster
    10.     '
    11.     ' Convert a currency value into an (American) English string
    12.     Function Writeout(ByVal N As Double) As String
    13.         Const Thousand = 1000@
    14.         Const Million = Thousand * Thousand
    15.         Const Billion = Thousand * Million
    16.         Const Trillion = Thousand * Billion
    17.  
    18.         If (N = 0@) Then Writeout = "zero" : Exit Function
    19.  
    20.         Dim Buf As String : If (N < 0@) Then Buf = "negative " Else Buf = ""
    21.         Dim Frac As Double : Frac = Math.Abs(N - Fix(N))
    22.         If (N < 0@ Or Frac <> 0@) Then N = Math.Abs(Fix(N))
    23.         Dim AtLeastOne As Integer : AtLeastOne = N >= 1
    24.  
    25.         If (N >= Trillion) Then
    26.  
    27.             Buf = Buf & EnglishDigitGroup(Int(N / Trillion)) & " trillion"
    28.             N = N - Int(N / Trillion) * Trillion ' Mod overflows
    29.             If (N >= 1@) Then Buf = Buf & " "
    30.         End If
    31.  
    32.         If (N >= Billion) Then
    33.  
    34.             Buf = Buf & EnglishDigitGroup(Int(N / Billion)) & " Billion"
    35.             N = N - Int(N / Billion) * Billion ' Mod still overflows
    36.             If (N >= 1@) Then Buf = Buf & " "
    37.         End If
    38.  
    39.         If (N >= Million) Then
    40.  
    41.             Buf = Buf & EnglishDigitGroup(N \ Million) & " Million"
    42.             N = N Mod Million
    43.             If (N >= 1@) Then Buf = Buf & " "
    44.         End If
    45.  
    46.         If (N >= Thousand) Then
    47.  
    48.             Buf = Buf & EnglishDigitGroup(N \ Thousand) & " Thousand"
    49.             N = N Mod Thousand
    50.             If (N >= 1@) Then Buf = Buf & " "
    51.         End If
    52.  
    53.         If (N >= 1@) Then
    54.  
    55.             Buf = Buf & EnglishDigitGroup(N)
    56.         End If
    57.  
    58.         If (Frac = 0@) Then
    59.             Buf = Buf & " Exactly"
    60.         ElseIf (Int(Frac * 100@) = Frac * 100@) Then
    61.             If AtLeastOne Then Buf = Buf & " and "
    62.             Buf = Buf & Format$(Frac * 100@, "00") & "/100"
    63.         Else
    64.             If AtLeastOne Then Buf = Buf & " and "
    65.             Buf = Buf & Format$(Frac * 100@, "00") & "/100"
    66.         End If
    67.  
    68.         Writeout = Buf
    69.     End Function
    70.  
    71.     ' Support function to be used only by English()
    72.     Private Function EnglishDigitGroup(ByVal N As Integer) As String
    73.         Const Hundred = " Hundred"
    74.         Const One = "One"
    75.         Const Two = "Two"
    76.         Const Three = "Three"
    77.         Const Four = "Four"
    78.         Const Five = "Five"
    79.         Const Six = "Six"
    80.         Const Seven = "Seven"
    81.         Const Eight = "Eight"
    82.         Const Nine = "Nine"
    83.         Dim Buf As String : Buf = ""
    84.         Dim Flag As Integer : Flag = False
    85.  
    86.         'Do hundreds
    87.         Select Case (N \ 100)
    88.             Case 0 : Buf = "" : Flag = False
    89.             Case 1 : Buf = One & Hundred : Flag = True
    90.             Case 2 : Buf = Two & Hundred : Flag = True
    91.             Case 3 : Buf = Three & Hundred : Flag = True
    92.             Case 4 : Buf = Four & Hundred : Flag = True
    93.             Case 5 : Buf = Five & Hundred : Flag = True
    94.             Case 6 : Buf = Six & Hundred : Flag = True
    95.             Case 7 : Buf = Seven & Hundred : Flag = True
    96.             Case 8 : Buf = Eight & Hundred : Flag = True
    97.             Case 9 : Buf = Nine & Hundred : Flag = True
    98.         End Select
    99.  
    100.         If (Flag <> False) Then N = N Mod 100
    101.         If (N > 0) Then
    102.             If (Flag <> False) Then Buf = Buf & " "
    103.         Else
    104.             EnglishDigitGroup = Buf
    105.             Exit Function
    106.         End If
    107.  
    108.         'Do tens (except teens)
    109.         Select Case (N \ 10)
    110.             Case 0, 1 : Flag = False
    111.             Case 2 : Buf = Buf & "Twenty" : Flag = True
    112.             Case 3 : Buf = Buf & "Thirty" : Flag = True
    113.             Case 4 : Buf = Buf & "Forty" : Flag = True
    114.             Case 5 : Buf = Buf & "Fifty" : Flag = True
    115.             Case 6 : Buf = Buf & "Sixty" : Flag = True
    116.             Case 7 : Buf = Buf & "Seventy" : Flag = True
    117.             Case 8 : Buf = Buf & "Eighty" : Flag = True
    118.             Case 9 : Buf = Buf & "Ninety" : Flag = True
    119.         End Select
    120.  
    121.         If (Flag <> False) Then N = N Mod 10
    122.         If (N > 0) Then
    123.             If (Flag <> False) Then Buf = Buf & "-"
    124.         Else
    125.             EnglishDigitGroup = Buf
    126.             Exit Function
    127.         End If
    128.  
    129.         'Do ones and teens
    130.         Select Case (N)
    131.             Case 0 ' do nothing
    132.             Case 1 : Buf = Buf & One
    133.             Case 2 : Buf = Buf & Two
    134.             Case 3 : Buf = Buf & Three
    135.             Case 4 : Buf = Buf & Four
    136.             Case 5 : Buf = Buf & Five
    137.             Case 6 : Buf = Buf & Six
    138.             Case 7 : Buf = Buf & Seven
    139.             Case 8 : Buf = Buf & Eight
    140.             Case 9 : Buf = Buf & Nine
    141.             Case 10 : Buf = Buf & "Ten"
    142.             Case 11 : Buf = Buf & "Eleven"
    143.             Case 12 : Buf = Buf & "Twelve"
    144.             Case 13 : Buf = Buf & "Thirteen"
    145.             Case 14 : Buf = Buf & "Fourteen"
    146.             Case 15 : Buf = Buf & "Fifteen"
    147.             Case 16 : Buf = Buf & "Sixteen"
    148.             Case 17 : Buf = Buf & "Seventeen"
    149.             Case 18 : Buf = Buf & "Eighteen"
    150.             Case 19 : Buf = Buf & "Nineteen"
    151.         End Select
    152.  
    153.         EnglishDigitGroup = Buf
    154.     End Function
    155.     '************ Code End **********

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Writing on checks

    Quote Originally Posted by tonyrueb
    I am making a program that will print on checks. I have it so it will ask for the amount in a $12.50 format, and all the other info. But as I’m sure all of you know you also have to write it out like “Twelve dollars and 50/100*************” seems simple but I don’t know how to go about this.
    You might choose to do it this way, but it is in no way required - at least not in the US.

    We produce payroll, health claim processing and other financial packages and write out out checks as:

    EXACTLY 12 DOLLARS AND 00 CENTS

    and then to the right of that we put ********12.00

    This is the accepted business practice in commercial applications (and some of our customers produce 100,000 checks or more a year!).

    Writing it out as words is more for a personal checking account (handwritten).

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

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



Click Here to Expand Forum to Full Width