Currently having trouble figuring out exactly how to convert my code in Visual B
ID: 664887 • Letter: C
Question
Currently having trouble figuring out exactly how to convert my code in Visual Basic. Right now I've got it set up for the program to execute when the user presses a button in a form. However, I need it to execute when the user selects the "calculate" option from a menu bar instead. I've included the code I have that runs when I press the calculate button below.
Private Sub CalculateButton_Click(sender As System.Object, e As System.EventArgs) Handles CalculateButton.Click
Dim SalesPrice, AdditionalCharge, Subtotal, SalesTax, Total, TradeIn, AmountDue As Decimal
'Converts the sales price'
SalesPrice = Decimal.Parse(SalesPriceBox.Text)
'If no data was entered into the trade-in box, then the amount is defaulted to 0'
If TradeBox.Text = "" Then
TradeBox.Text = 0
End If
'Converts the trade-in allowance'
TradeIn = Decimal.Parse(TradeBox.Text)
'Includes exterior finish charges'
If PearlizedRadio.Checked Then
AdditionalCharge = PearlizedCharge
ElseIf CustomRadio.Checked Then
AdditionalCharge = CustomizedCharge
End If
'Includes Accessories charges'
If StereoCheck.Checked Then
AdditionalCharge = AdditionalCharge + StereoCharge
End If
If InteriorCheck.Checked Then
AdditionalCharge = AdditionalCharge + LeatherCharge
End If
If NavigationCheck.Checked Then
AdditionalCharge = AdditionalCharge + NavigationCharge
End If
'Calculates Subtotal before tax'
Subtotal = SalesPrice + AdditionalCharge
'Calculates tax amount'
SalesTax = Subtotal * TaxRate
'Calculates Total before trade-in value'
Total = Subtotal + SalesTax
'Calculates Amount Due'
AmountDue = Total - TradeIn
'Displays amounts in text boxes'
SalesPriceBox.Text = SalesPrice.ToString("C")
AccessoriesBox.Text = AdditionalCharge.ToString("C")
SubtotalBox.Text = Subtotal.ToString("C")
SalesTaxBox.Text = SalesTax.ToString("C")
TotalBox.Text = Total.ToString("C")
TradeBox.Text = TradeIn.ToString("C")
DueBox.Text = AmountDue.ToString("C")
With TradeBox()
.Focus()
.SelectAll()
End With
With SalesPriceBox()
.Focus()
.SelectAll()
End With
End Sub
Explanation / Answer
so what you need to do. is you need to create a function called calculate.
place all your logic, you have written for the button in that function
and from the main program
just call your function.
e.g
Private Function ComputePay() As Decimal{
.............................
.......................logic goes here
}
Call function ComputePay
GrossPayDecimal = ComputePay()
. . . more code follows
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.