Question

Visual Basic Code.

224 Chapter 5 General Procedures In Exercises 14 and 15, rewrite the program using a Function instead of a Sub procedure. 14. Private Sub btnCalculate Click (... Handles btnCalculate.Click Dim firstNumber, secondNumber As Integer firstNumber = 4 Triple (firstNumber, secondNumber) txtResult. Text = CStr (secondNumber) End Sub Sub Triple (firstNumber As Integer, ByRef secondNumber As Integer) secondNumber = 3 * firstNumber End Sub 15. Private Sub btnCalculate Click(.) Handles btncalculate.Click Dim price, salesTaxRate, cost As Decima price = 29 . 95D salesTaxRate = 0。05D Findcost (price, salesTaxRate, cost) txtResult . Text cost. ToString ( C ) End Sub As Decimal) Sub FindCost (price As Decimal, salesTaxRate As Decimal, ByRef cost cost = price * (1 + salesTaxRate) End Sub

0 0
Add a comment Improve this question Transcribed image text
Answer #1

14.

Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim firstNumber, secondNumber As Integer
firstNumber = 4
secondNumber = Triple(firstNumber, secondNumber)
txtResult.Text = CStr(secondNumber)

End Sub
Function Triple(firstNumber As Integer, ByRef secondNumber As Integer)
secondNumber = 3 * firstNumber
Triple = secondNumber 'function does return a value ie secondNumber unlike sub procedure
End Function
End Class

Fle Edit View Project Build Debug Team Tools Test Analyce WindowHep ign in any CPU トCotirut Process 12548 FunctionDem.shost.eycle Ee Ted FomlvbiX Formab [Design xpio Form Triple Private Sub bcalculateClick(sender As object, e As Eventargs) Handles btncalculate.Click Search Solton Explorer (Col. Din firstlumber, secondtumber As Integer firstlurber4 secondiumber Triple(firstmber, seconduber txtResult.Text·CStr (seconduter) Selution FunctionDemo (1 project My Project References Appconfig Ferm End Sub Function Triplefirstluber As Integer, ByRef secondvumber As Intege-) seconduber 3firsthumber Triple seconFom End Function End Class Calcuade 00% Output outpat froms The thread 8298 has exited with code 8 (exe) FunctionDeso.vshost.exe (CLR 4.8.38319: Functiondeno.vshost exe): Loaded CNOOWs dcrosoft.NetLasseebly Gc 54 System. Configuration v4.e-4.e.e.e be3f5f711a5Ba3a Systes. Configuration.dll. Skipped lcading symbols. Modu t.exe (CLR 4.8.38319: FunctLonDeno.vshost exe) Leeded c: sivisual studio 2015 Projects FunctionDeno FunctionDeno\binyDebugi Function.exe Symbols loaded Function nomost exe CLR 4.8.38319 Function mo vs ost exe Leaded C: NT O S crosoft Netiasse blyiSC SILSystem Runt Re ot ng 4.อ 4 อ.อ.อ b77a5c56293eensyste Auti Re ting dll pped loading syndels Solution Explorer 224AM OType here to search 0

15.

Public Class Form1
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim price, salesTaxRate, cost As Decimal
price = 29.95D
salesTaxRate = 0.05D
cost = FindCost(price, salesTaxRate, cost)

txtResult.Text = cost.ToString("C")

End Sub

Function FindCost(price As Decimal, saleTaxRate As Decimal, ByRef cost As Decimal)
cost = price * (1 + saleTaxRate)
FindCost = cost ''function does return a value ie cost unlike sub procedure
End Function
End Class

Add a comment
Know the answer?
Add Answer to:
Visual Basic Code. 224 Chapter 5 General Procedures In Exercises 14 and 15, rewrite the program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with this problem in Visual Basic 2012: Write a program that allows the...

    I need help with this problem in Visual Basic 2012: Write a program that allows the user to specify two numbers and then adds, subtracts, multiplies, or divides them when the user clicks on the appropriate button. The output should give the type of arithmetic performed and the result. Whenever one of the numbers in an input text box is changed, the output text box should be cleared. Also, if the number 0 is entered into the second text box,...

  • The Murach's Visual Basic 2015 Book And Visual Studio Exercise 7-2 Enhance the Invoice Total application...

    The Murach's Visual Basic 2015 Book And Visual Studio Exercise 7-2 Enhance the Invoice Total application If you did exercise 6-1 in the last chapter, this exercise asks you to add data validation and exception handling to it. 1. Copy the Invoice Total application from your C:\VB 2015\Chapter 06 directory to your Chapter 07 directory. This should be your solution to exercise 6-1 of the last chapter. 2. If your application has both a Sub procedure and a Function procedure...

  • Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb...

    Visual Basic 2015: Extra 18-1 Use inheritance with the Inventory Maintenance Application Source Code: 1. frmNewItem.vb Public Class frmNewItem Public InvItem As InvItem Private Sub frmNewItem_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.LoadComboBox() End Sub Private Sub LoadComboBox() cboSizeOrManufacturer.Items.Clear() If rdoPlant.Checked Then cboSizeOrManufacturer.Items.Add("1 gallon") cboSizeOrManufacturer.Items.Add("5 gallon") cboSizeOrManufacturer.Items.Add("15 gallon") cboSizeOrManufacturer.Items.Add("24-inch box") cboSizeOrManufacturer.Items.Add("36-inch box") Else cboSizeOrManufacturer.Items.Add("Bayer") cboSizeOrManufacturer.Items.Add("Jobe's") cboSizeOrManufacturer.Items.Add("Ortho") cboSizeOrManufacturer.Items.Add("Roundup") cboSizeOrManufacturer.Items.Add("Scotts") End If End Sub Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click If IsValidData() Then InvItem = New InvItem(CInt(txtItemNo.Text),...

  • I am trying to build a program in Visual Basic that allows user to enter an...

    I am trying to build a program in Visual Basic that allows user to enter an objects mass and velocity and to display the Kinetic energy. The application should have a function KineticEnergy that accepts a moving objects mass and velocity as arguments. The function should return the objects KE. i get these three errors when trying to run the program I need help how would I fix this so it runs successfully? Thanks in advance! Start 16 ml.vb* +...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT