Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to do a Visual Basic Project. I want to get out put After Entering t

ID: 3857642 • Letter: I

Question

I am trying to do a Visual Basic Project. I want to get out put After Entering the followings Inputs:

Inputs:

# BeefDogs      1 (Entered)

# PorkDogs      2 (Entered)

# TurkeyDogs   3 (Entered)

I have to press Subtotal Button first

then Calculate Order Button

When I do that I get 0 values for the following in text boxes

Subtotal     0.00

Sales Tax 00

Total Cost 0.00

Please my codes shown below. Could you please help me. I really appreciate your help

Public Class Dan

Private Sub Label4_Click(sender As Object, e As EventArgs) Handles TurkeyDogs1.Click

End Sub

Private Sub Label3_Click(sender As Object, e As EventArgs) Handles SubTotal1.Click

End Sub

Private Sub CalculateOrder_Click(sender As Object, e As EventArgs) Handles CalculateOrder.Click

'variables declaration

Dim intNumBeef, intNumPork, intNumTurkey, intTotDogs As Integer

Dim db1Subtotal, db1SalesTaxAmt, db1TotalCost As Double

Const DBL_COST_PER_DOG As Double = 1.99

Const DBL_SALES_TAX_RATE As Double = 0.07

'Converting Variables

intNumBeef = Convert.ToInt32(BeefDogs.Text)

intNumPork = Convert.ToInt32(PorkDogs.Text)

intNumTurkey = Convert.ToInt32(TurkeyDogs.Text)

'Calculation

db1Subtotal = intTotDogs * DBL_COST_PER_DOG

db1SalesTaxAmt = db1Subtotal * DBL_SALES_TAX_RATE

db1TotalCost = db1Subtotal + db1SalesTaxAmt

'Converting to two decimals

SubTotal.Text = db1Subtotal.ToString("c2")

SalesTax.Text = db1SalesTaxAmt.ToString("c2")

TotalCost.Text = db1TotalCost.ToString("c2")

End Sub

Private Sub BeefDogs_TextChanged(sender As Object, e As EventArgs) Handles BeefDogs.TextChanged

Dim intNumBeef = Convert.ToInt32(BeefDogs.Text)

End Sub

Private Sub TextBox7_TextChanged(sender As Object, e As EventArgs) Handles PorkDogs.TextChanged

Dim intNumPork = Convert.ToInt32(BeefDogs.Text)

End Sub

Private Sub Exit1_Click(sender As Object, e As EventArgs) Handles Exit1.Click

Me.Close()

End Sub

Private Sub TurkeyDogs_TextChanged(sender As Object, e As EventArgs) Handles TurkeyDogs.TextChanged

Dim intNumTurkey = Convert.ToInt32(BeefDogs.Text)

End Sub

End Class

Explanation / Answer

Hi,

Please replace the below lines with new lines and see if it works.

Lines to be changed-

'Converting to two decimals

SubTotal.Text = db1Subtotal.ToString("c2")

SalesTax.Text = db1SalesTaxAmt.ToString("c2")

TotalCost.Text = db1TotalCost.ToString("c2")

Replacement Lines:

'Converting to two decimals

SubTotal.Text = Cstr(db1Subtotal)

SalesTax.Text = Cstr(db1SalesTaxAmt)

TotalCost.Text = Cstr(db1TotalCost)

or you can try below replacement-

'Converting to two decimals

SubTotal.Text = db1Subtotal

SalesTax.Text = db1SalesTaxAmt

TotalCost.Text = db1TotalCost

Rest all code looks fine to me. Please comment me if you still see such issue.

Regards,

Vinay Singh

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote