Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

3rd semester web applications major. Having problem with code. Professor is no help.?

Unfortunately, my professors answer to any question is to simply give you the code. Here is my dilemna. I need to code an inventory application, which will give the book title, the quantity in stock and the total cost. I need to write the code to deliver both the hard back quantity, the paperback quantity and then the 2 combined (cost and inventory) My code works except for the combined cost. I keep getting $0.00. Help!

The code for the rest works. The code for the combined cost of the paperback + hardback does not. I tried adding the Val function and it just crashes the application. The code that wil not work is pasted below.Thanks for any help!

Me.uiCostLabel.Text = Me.uiCostHardText.Text * Me.uiQuantityHardText.Text + Me.uiPaperQuantityText.Text * Me.uiPaperCostText.Text

Me.uiCostLabel.Text = Format(Me.uiCostLabel.Text, "currency")

Update:

I would prefer an explanation rather than a simple code solution response. This will help me understand what I am doing incorrectly. Thanks! :D

Update 2:

Visual Basic.net application

Update 3:

Thanks for your reply. However, as I stated I am a student, we have not yet studied Dim and whatever else it was you mentioned in your reply. Therefore the solution has to be something we have already reviewed. We have gotten to Val(Me.blahblahblah) but that is the extent of it. Any suggestions?

Update 4:

Thanks for your reply. However, as I stated I am a student, we have not yet studied Dim and whatever else it was you mentioned in your reply. Therefore the solution has to be something we have already reviewed. We have gotten to Val(Me.blahblahblah) but that is the extent of it. Any suggestions?

1 Answer

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    You'd probably find you do better if you convert all your values to integers / doubles before performing math on them:

    Dim HardTextCost As Decimal = Convert.ToDecimal( Me.uiCostHardText .Text )

    Dim HardTextQty As Integer = Convert.ToInt16( Me.uiQuantityHardText.Text )

    Dim SoftTextCost As Decimal = Convert.ToDecimal( uiPaperQuantityText.Text )

    Dim SoftTextQty As Integer = Convert.ToInt16( Me.uiPaperCostText.Text )

    You also are probably having issues with operator precedence:

    Dim TotalCost As Decimal = (HardTextCost * HardTextQty) + (SoftTextCost * SoftTextQty)

    You should use ToString to send other variable types to strings:

    Me.uiCostLabel.Text = TotalCost.ToString("C")

Still have questions? Get your answers by asking now.