Answer to Question #239616 in Visual Basic for Guddu

Question #239616
When the user clicks the calculate button your program should calculate the subtotal,taxes,shipping and total with the following requirements
PST (6%)and GST (5%)are applied only to items when the corresponding check box is checked
Items value are used in calculations only if the item text box contains a positive number
1
Expert's answer
2021-09-20T11:09:02-0400
Public Class frmCalculateSubtotal


    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        Dim amount As Double
        Double.TryParse(txtAmount.Text, amount)
        Dim subtotal As Double = amount
        Dim taxes As Double = subtotal * 0.1
        Dim shipping As Double = subtotal * 0.1




        If cbPST6.Checked Then
            taxes = subtotal * 0.06
        End If


        If cbGST5.Checked Then
            shipping = subtotal * 0.05
        End If


        Dim total As Double = subtotal + taxes + shipping


        txtSubtotal.Text = subtotal.ToString("C")
        txtTaxes.Text = taxes.ToString("C")
        txtShipping.Text = shipping.ToString("C")
        txtTotal.Text = total.ToString("C")
    End Sub
End Class



<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmCalculateSubtotal
    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.btnCalculate = New System.Windows.Forms.Button()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.txtAmount = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.txtSubtotal = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.txtTaxes = New System.Windows.Forms.TextBox()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.txtShipping = New System.Windows.Forms.TextBox()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.txtTotal = New System.Windows.Forms.TextBox()
        Me.cbPST6 = New System.Windows.Forms.CheckBox()
        Me.cbGST5 = New System.Windows.Forms.CheckBox()
        Me.SuspendLayout()
        '
        'btnCalculate
        '
        Me.btnCalculate.Location = New System.Drawing.Point(150, 196)
        Me.btnCalculate.Name = "btnCalculate"
        Me.btnCalculate.Size = New System.Drawing.Size(75, 23)
        Me.btnCalculate.TabIndex = 0
        Me.btnCalculate.Text = "Calculate"
        Me.btnCalculate.UseVisualStyleBackColor = True
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(32, 32)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(73, 13)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Enter amount:"
        '
        'txtAmount
        '
        Me.txtAmount.Location = New System.Drawing.Point(125, 29)
        Me.txtAmount.Name = "txtAmount"
        Me.txtAmount.Size = New System.Drawing.Size(100, 20)
        Me.txtAmount.TabIndex = 2
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(32, 85)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(49, 13)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Subtotal:"
        '
        'txtSubtotal
        '
        Me.txtSubtotal.Location = New System.Drawing.Point(125, 82)
        Me.txtSubtotal.Name = "txtSubtotal"
        Me.txtSubtotal.ReadOnly = True
        Me.txtSubtotal.Size = New System.Drawing.Size(100, 20)
        Me.txtSubtotal.TabIndex = 2
        Me.txtSubtotal.TabStop = False
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(32, 111)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(39, 13)
        Me.Label3.TabIndex = 1
        Me.Label3.Text = "Taxes:"
        '
        'txtTaxes
        '
        Me.txtTaxes.Location = New System.Drawing.Point(125, 108)
        Me.txtTaxes.Name = "txtTaxes"
        Me.txtTaxes.ReadOnly = True
        Me.txtTaxes.Size = New System.Drawing.Size(100, 20)
        Me.txtTaxes.TabIndex = 2
        Me.txtTaxes.TabStop = False
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(32, 137)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(51, 13)
        Me.Label4.TabIndex = 1
        Me.Label4.Text = "Shipping:"
        '
        'txtShipping
        '
        Me.txtShipping.Location = New System.Drawing.Point(125, 134)
        Me.txtShipping.Name = "txtShipping"
        Me.txtShipping.ReadOnly = True
        Me.txtShipping.Size = New System.Drawing.Size(100, 20)
        Me.txtShipping.TabIndex = 2
        Me.txtShipping.TabStop = False
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(32, 163)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(34, 13)
        Me.Label5.TabIndex = 1
        Me.Label5.Text = "Total:"
        '
        'txtTotal
        '
        Me.txtTotal.Location = New System.Drawing.Point(125, 160)
        Me.txtTotal.Name = "txtTotal"
        Me.txtTotal.ReadOnly = True
        Me.txtTotal.Size = New System.Drawing.Size(100, 20)
        Me.txtTotal.TabIndex = 2
        Me.txtTotal.TabStop = False
        '
        'cbPST6
        '
        Me.cbPST6.AutoSize = True
        Me.cbPST6.Location = New System.Drawing.Point(68, 59)
        Me.cbPST6.Name = "cbPST6"
        Me.cbPST6.Size = New System.Drawing.Size(70, 17)
        Me.cbPST6.TabIndex = 3
        Me.cbPST6.Text = "PST (6%)"
        Me.cbPST6.UseVisualStyleBackColor = True
        '
        'cbGST5
        '
        Me.cbGST5.AutoSize = True
        Me.cbGST5.Location = New System.Drawing.Point(154, 59)
        Me.cbGST5.Name = "cbGST5"
        Me.cbGST5.Size = New System.Drawing.Size(71, 17)
        Me.cbGST5.TabIndex = 3
        Me.cbGST5.Text = "GST (5%)"
        Me.cbGST5.UseVisualStyleBackColor = True
        '
        'frmCalculateSubtotal
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(259, 236)
        Me.Controls.Add(Me.cbGST5)
        Me.Controls.Add(Me.cbPST6)
        Me.Controls.Add(Me.txtTotal)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.txtShipping)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.txtTaxes)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.txtSubtotal)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.txtAmount)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.btnCalculate)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmCalculateSubtotal"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Calculate Subtotal"
        Me.ResumeLayout(False)
        Me.PerformLayout()


    End Sub
    Friend WithEvents btnCalculate As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtAmount As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtSubtotal As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents txtTaxes As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents txtShipping As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents txtTotal As System.Windows.Forms.TextBox
    Friend WithEvents cbPST6 As System.Windows.Forms.CheckBox
    Friend WithEvents cbGST5 As System.Windows.Forms.CheckBox


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