Answer to Question #256441 in Visual Basic for xxx

Question #256441

Write a VB program to calculate the Total amount to pay after included 6% GST and 10% Service Tax. Then, calculate the change value after payment.

*set the Enabled properties of service tax, GST, total and change text boxes to False

The Service Tax, GST, and Total will be calculated while the TextChanged event of the Enter Amount textbox is triggered.

The change value will be displayed in the Change textbox while the Clicked event of the Pay button is triggered.


1
Expert's answer
2021-10-25T09:39:41-0400
Public Class frmCalculateTotalAmount
    
    Private total As Double
    Private Sub txtInputAmount_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInputAmount.TextChanged


        Dim inputAmount As Double
        Double.TryParse(txtInputAmount.Text, inputAmount)


        Dim GST As Double = inputAmount * 0.06
        Dim serviceTax As Double = inputAmount * 0.1
        total = inputAmount + GST + serviceTax
        txtGST.Text = GST.ToString("N2")
        txtServiceTax.Text = serviceTax.ToString("N2")
        txtTotal.Text = total.ToString("N2")
        If total > 0 Then
            btnPay.Enabled = True
        Else
            btnPay.Enabled = False
        End If


    End Sub


    Private Sub btnPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPay.Click
        Dim amount As Double
        Double.TryParse(txtAmount.Text, amount)
        Dim change As Double = amount - total
        txtChange.Text = change.ToString("N2")
    End Sub
End Class





<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmCalculateTotalAmount
    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.txtChange = New System.Windows.Forms.TextBox()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.txtTotal = New System.Windows.Forms.TextBox()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.txtServiceTax = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.txtGST = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.txtAmount = New System.Windows.Forms.TextBox()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.txtInputAmount = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.btnPay = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'txtChange
        '
        Me.txtChange.Location = New System.Drawing.Point(102, 146)
        Me.txtChange.Name = "txtChange"
        Me.txtChange.ReadOnly = True
        Me.txtChange.Size = New System.Drawing.Size(100, 20)
        Me.txtChange.TabIndex = 12
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Location = New System.Drawing.Point(49, 149)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(47, 13)
        Me.Label6.TabIndex = 10
        Me.Label6.Text = "Change:"
        '
        'txtTotal
        '
        Me.txtTotal.Location = New System.Drawing.Point(102, 94)
        Me.txtTotal.Name = "txtTotal"
        Me.txtTotal.ReadOnly = True
        Me.txtTotal.Size = New System.Drawing.Size(100, 20)
        Me.txtTotal.TabIndex = 15
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(62, 97)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(34, 13)
        Me.Label5.TabIndex = 11
        Me.Label5.Text = "Total:"
        '
        'txtServiceTax
        '
        Me.txtServiceTax.Location = New System.Drawing.Point(102, 68)
        Me.txtServiceTax.Name = "txtServiceTax"
        Me.txtServiceTax.ReadOnly = True
        Me.txtServiceTax.Size = New System.Drawing.Size(100, 20)
        Me.txtServiceTax.TabIndex = 14
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(5, 71)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(96, 13)
        Me.Label3.TabIndex = 9
        Me.Label3.Text = "Service Tax (10%):"
        '
        'txtGST
        '
        Me.txtGST.Location = New System.Drawing.Point(102, 42)
        Me.txtGST.Name = "txtGST"
        Me.txtGST.ReadOnly = True
        Me.txtGST.Size = New System.Drawing.Size(100, 20)
        Me.txtGST.TabIndex = 17
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(42, 45)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(55, 13)
        Me.Label2.TabIndex = 8
        Me.Label2.Text = "GST (6%):"
        '
        'txtAmount
        '
        Me.txtAmount.Location = New System.Drawing.Point(102, 120)
        Me.txtAmount.Name = "txtAmount"
        Me.txtAmount.Size = New System.Drawing.Size(100, 20)
        Me.txtAmount.TabIndex = 16
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(23, 123)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(73, 13)
        Me.Label4.TabIndex = 6
        Me.Label4.Text = "Enter amount:"
        '
        'txtInputAmount
        '
        Me.txtInputAmount.Location = New System.Drawing.Point(102, 16)
        Me.txtInputAmount.Name = "txtInputAmount"
        Me.txtInputAmount.Size = New System.Drawing.Size(100, 20)
        Me.txtInputAmount.TabIndex = 13
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(23, 19)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(73, 13)
        Me.Label1.TabIndex = 7
        Me.Label1.Text = "Enter amount:"
        '
        'btnPay
        '
        Me.btnPay.Enabled = False
        Me.btnPay.Location = New System.Drawing.Point(102, 172)
        Me.btnPay.Name = "btnPay"
        Me.btnPay.Size = New System.Drawing.Size(100, 23)
        Me.btnPay.TabIndex = 4
        Me.btnPay.Text = "Pay"
        Me.btnPay.UseVisualStyleBackColor = True
        '
        'frmCalculateTotalAmount
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(221, 216)
        Me.Controls.Add(Me.txtChange)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.txtTotal)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.txtServiceTax)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.txtGST)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.txtAmount)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.txtInputAmount)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.btnPay)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmCalculateTotalAmount"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Calculate Total Amount"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents txtChange As System.Windows.Forms.TextBox
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents txtTotal As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents txtServiceTax As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents txtGST As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtAmount As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents txtInputAmount As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnPay As System.Windows.Forms.Button

End Class





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS