Visual Basic
Write the code snippit for the btnCalculate event handler based upon the following pseudo-code and User Interface. Don’t forget to create all variables needed and perform all necessary data conversions (ToString,TryParse). Use the control names listed in the pseudo-code. The pseudo-code is as follows
Create variables for item cost (dblCost) and item amount (dblAmount)
Get the item cost from tbxCost and place it in the variable(dblCost)
Gt item amount from tbxAmount and place in it the variable (dblAmount)
If the item amount or item cost is zero
Display the message “Enter amount and cost” in the label (lblResult)
Else
Calculate the total cost by multiplying the item cost by the item amount
Display the total cost in lblResult as currency with two decimal places
Endif
Code:=
Dim dblCost, dblAmount As Integer
Dim tcost As Double
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
dblCost =
Val(tbxCost.Text)
dblAmount =
Val(tbxAmount.Text)
If dblCost = 0 Or
dblAmount = 0 Then
lblResult.Text = "Enter the Cost and Amount"
Else
tcost = dblCost * dblAmount
lblResult.Text = "Total cost is Rs. " & FormatNumber(tcost,
2)
End If
End Sub
Output:=
Get Answers For Free
Most questions answered within 1 hours.