In correspondence to the flowchart shown in Figure 1.1, develop an application that will store the salesperson’s code, which is to be entered in the codeTextBox, in an Integer variable named code. The application will need to store the sales amount, which is to be entered in the salesTextBox, in a decimal variable named sales. Display the result of the calculation, or the error message, in the messageLabel. Name your Program SalesAccount.
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class mainForm
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
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.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label()
Me.codeTextBox = New System.Windows.Forms.TextBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.salesTextBox = New System.Windows.Forms.TextBox()
Me.btnCalculate = New System.Windows.Forms.Button()
Me.messageLabel = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(24, 40)
Me.Label1.Margin = New System.Windows.Forms.Padding(5, 0, 5, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(219, 20)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Enter the salesperson’s code:"
'
'codeTextBox
'
Me.codeTextBox.Location = New System.Drawing.Point(279, 35)
Me.codeTextBox.Margin = New System.Windows.Forms.Padding(5)
Me.codeTextBox.Name = "codeTextBox"
Me.codeTextBox.Size = New System.Drawing.Size(103, 26)
Me.codeTextBox.TabIndex = 1
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(68, 80)
Me.Label2.Margin = New System.Windows.Forms.Padding(5, 0, 5, 0)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(178, 20)
Me.Label2.TabIndex = 0
Me.Label2.Text = "Enter the sales amount:"
'
'salesTextBox
'
Me.salesTextBox.Location = New System.Drawing.Point(279, 75)
Me.salesTextBox.Margin = New System.Windows.Forms.Padding(5)
Me.salesTextBox.Name = "salesTextBox"
Me.salesTextBox.Size = New System.Drawing.Size(103, 26)
Me.salesTextBox.TabIndex = 2
'
'btnCalculate
'
Me.btnCalculate.Location = New System.Drawing.Point(279, 125)
Me.btnCalculate.Margin = New System.Windows.Forms.Padding(5)
Me.btnCalculate.Name = "btnCalculate"
Me.btnCalculate.Size = New System.Drawing.Size(103, 35)
Me.btnCalculate.TabIndex = 3
Me.btnCalculate.Text = "Calculate"
Me.btnCalculate.UseVisualStyleBackColor = True
'
'messageLabel
'
Me.messageLabel.AutoSize = True
Me.messageLabel.Location = New System.Drawing.Point(154, 171)
Me.messageLabel.Margin = New System.Windows.Forms.Padding(5, 0, 5, 0)
Me.messageLabel.Name = "messageLabel"
Me.messageLabel.Size = New System.Drawing.Size(0, 20)
Me.messageLabel.TabIndex = 0
'
'mainForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(9.0!, 20.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(421, 215)
Me.Controls.Add(Me.btnCalculate)
Me.Controls.Add(Me.salesTextBox)
Me.Controls.Add(Me.messageLabel)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.codeTextBox)
Me.Controls.Add(Me.Label1)
Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Margin = New System.Windows.Forms.Padding(5)
Me.MaximizeBox = False
Me.Name = "mainForm"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Sales Account"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents codeTextBox As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents salesTextBox As System.Windows.Forms.TextBox
Friend WithEvents btnCalculate As System.Windows.Forms.Button
Friend WithEvents messageLabel As System.Windows.Forms.Label
End Class
Main form
Public Class mainForm
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim code As Integer = 0
Dim sales As Decimal = 0
If Integer.TryParse(codeTextBox.Text, code) = False Then
messageLabel.Text = "Enter a correct code."
Return
End If
If Decimal.TryParse(salesTextBox.Text, sales) = False Then
messageLabel.Text = "Enter a correct sales."
End If
messageLabel.Text = "The total sales: " + sales.ToString("C")
End Sub
End Class
Comments
Leave a comment