Mike Bailey
Well-known member
Code:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim BigOnes(9) As String
Dim SmallOnes(19) As String
Dim Dollars As String
Dim Cents As String
Dim Words As String
Dim Chunk As String
Dim Digits As Short
Dim LeftDigit As Short
Dim RightDigit As Short
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
This call is required by the Windows Form Designer.
InitializeComponent()
Add any initialization after the InitializeComponent() call
End Sub
Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
NOTE: The following procedure is required by the Windows Form Designer
It can be modified using the Windows Form Designer.
Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents txtAmount As System.Windows.Forms.TextBox
Friend WithEvents txtWrite As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Button1 = New System.Windows.Forms.Button
Me.txtAmount = New System.Windows.Forms.TextBox
Me.txtWrite = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.SuspendLayout()
Label1
Me.Label1.BackColor = System.Drawing.Color.Transparent
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(96, 48)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Michael S. Bailey 1825 NE. 3rd Renton WA, 89056"
Label2
Me.Label2.BackColor = System.Drawing.Color.Transparent
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.ForeColor = System.Drawing.Color.Red
Me.Label2.Location = New System.Drawing.Point(376, 0)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(88, 24)
Me.Label2.TabIndex = 1
Me.Label2.Text = "38069"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.TopCenter
Button1
Me.Button1.Location = New System.Drawing.Point(16, 152)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(96, 24)
Me.Button1.TabIndex = 2
Me.Button1.Text = "Button1"
txtAmount
Me.txtAmount.Location = New System.Drawing.Point(360, 56)
Me.txtAmount.Name = "txtAmount"
Me.txtAmount.Size = New System.Drawing.Size(80, 20)
Me.txtAmount.TabIndex = 3
Me.txtAmount.Text = ""
txtWrite
Me.txtWrite.BackColor = System.Drawing.Color.PaleGreen
Me.txtWrite.Location = New System.Drawing.Point(24, 96)
Me.txtWrite.Name = "txtWrite"
Me.txtWrite.ReadOnly = True
Me.txtWrite.Size = New System.Drawing.Size(424, 20)
Me.txtWrite.TabIndex = 4
Me.txtWrite.Text = ""
Label3
Me.Label3.BackColor = System.Drawing.Color.Transparent
Me.Label3.Font = New System.Drawing.Font("Monotype Corsiva", 15.75!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(288, 160)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(160, 24)
Me.Label3.TabIndex = 5
Me.Label3.Text = "Michael S. Bailey"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.BottomCenter
Me.Label3.Visible = False
Label4
Me.Label4.BackColor = System.Drawing.Color.Transparent
Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label4.Location = New System.Drawing.Point(288, 56)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(64, 24)
Me.Label4.TabIndex = 6
Me.Label4.Text = "Amount"
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
Form1
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.ActiveBorder
Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
Me.ClientSize = New System.Drawing.Size(456, 189)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.txtWrite)
Me.Controls.Add(Me.txtAmount)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.MaximumSize = New System.Drawing.Size(464, 216)
Me.MinimumSize = New System.Drawing.Size(464, 216)
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Bank of America"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Public Sub ParseChunk()
Digits = CShort(Mid(Chunk, 1, 1))
If Digits > 0 Then
Words = Words & " " & SmallOnes(Digits) & " Hundred"
End If
Digits = CShort(Mid(Chunk, 2, 2))
If Digits > 19 Then
LeftDigit = CShort(Mid(Chunk, 2, 1))
RightDigit = CShort(Mid(Chunk, 3, 1))
Words = Words & " " & BigOnes(LeftDigit)
If RightDigit > 0 Then
Words = Words & " " & SmallOnes(RightDigit)
End If
Else
If Digits > 0 Then
Words = Words & " " & SmallOnes(Digits)
End If
End If
End Sub
Private Sub form1_load()
BigOnes(1) = "Ten"
BigOnes(2) = "Twenty"
BigOnes(3) = "Thirty"
BigOnes(4) = "Forty"
BigOnes(5) = "Fifty"
BigOnes(6) = "Sixty"
BigOnes(7) = "Seventy"
BigOnes(8) = "Eighty"
BigOnes(9) = "Ninety"
SmallOnes(1) = "One"
SmallOnes(2) = "Two"
SmallOnes(3) = "Three"
SmallOnes(4) = "Four"
SmallOnes(5) = "Five"
SmallOnes(6) = "Six"
SmallOnes(7) = "Seven"
SmallOnes(8) = "Eight"
SmallOnes(9) = "Nine"
SmallOnes(10) = "Ten"
SmallOnes(11) = "Eleven"
SmallOnes(12) = "Twelve"
SmallOnes(13) = "Thirteen"
SmallOnes(14) = "Fourteen"
SmallOnes(15) = "Fifteen"
SmallOnes(16) = "Sixteen"
SmallOnes(17) = "Seventeen"
SmallOnes(18) = "Eighteen"
SmallOnes(19) = "Nineteen"
txtAmount.Text = Format(txtAmount.Text, "000000.00")
Dollars = Left(txtAmount.Text, 6)
Cents = Right(txtAmount.Text, 2)
Words = ""
check to make sure incoming number is not too large
If Dollars > 999999 Then
txtAmount.Text = "Dollar amount is too large"
Exit Sub
End If
separate the dollars into chunks
If Dollars = 0 Then
Words = "Zero"
Else
first do the thousands
I get error on chunk and left-----> Chunk = Left(Dollars, 3)
If CDbl Chunk > 0 Then
And here----> ParseChunk()
Words = Words & " Thousand"
End If
do the rest of the dollars
Chunk = Right(Dollars, 3)
If CDbl Chunk > 0 Then
ParseChunk()
End If
End If
concatenate the cents and display
If Cents = 0 Then Cents = "No"
Words = Words & " and " & Cents & "/100"
txtWrite.Text = Words
Exit Sub
ParseChunk:
Digits = Mid(Chunk, 1, 1)
If Digits > 0 Then
Words = Words & " " & SmallOnes(Digits) & " Hundred"
End If
Digits = Mid(Chunk, 2, 2)
If Digits > 19 Then
LeftDigit = Mid(Chunk, 2, 1)
RightDigit = Mid(Chunk, 3, 1)
Words = Words & " " & BigOnes(LeftDigit)
If RightDigit > 0 Then
Words = Words & " " & SmallOnes(RightDigit)
End If
Else
If Digits > 0 Then
Words = Words & " " & SmallOnes(Digits)
End If
End If
Return
Label3.Visible = True
End Sub
End Class