1 / 16

Mathematical and Business Functions

Mathematical and Business Functions. Chapter 8. 8.1 Built-in Mathematical Function. Visual Basic includes several built-in mathematical functions Abs Sqr Sgn IsNumeric Round Format Pmt PV FV. Abs(number). Returns the absolute value of a number Form: Abs(number) Example:

aria
Download Presentation

Mathematical and Business Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Mathematical and Business Functions Chapter 8

  2. 8.1 Built-in Mathematical Function • Visual Basic includes several built-in mathematical functions • Abs • Sqr • Sgn • IsNumeric • Round • Format • Pmt • PV • FV

  3. Abs(number) • Returns the absolute value of a number • Form: Abs(number) • Example: Dim intNum As Integer intNum = -5 lblAnswer.Caption = Abs(intNum) ‘ 5 will be displayed

  4. Sqr(number) • Returns the square root of a number • You can not take a square root of a negative number • Form: Sqr(number) • Example: Dim intNum As Integer intNum = 9 lblAns.Caption = Sqr(intNum) ‘ 3 will be displayed

  5. Sgn(number) • Returns 1,-1,or 0 when the numeric argument is positive, negative or 0 respectively. • Form: Sgn(number) • Example: Dim intNum As Integer intNum = -5 lblAns.Caption = Sgn(intNum) ‘-1 is displayed intNum = 3 lblAns.Caption = Sgn(intNum) ‘1 is displayed

  6. 8.2 The IsNumeric Function • Returns True if its argument can be evaluated as a number and False if it cannot. • Form: IsNumeric(argument) • Example: Dim strString As String strString = “123” lblAns.Caption = IsNumeric(strString) ‘True strString = “abc” lblAns.Caption = IsNumeric(strString) ‘False lblAns.Caption = IsNumeric(“2+4”) ‘False lblAns.Caption = IsNumeric(2+4) ‘ True

  7. 8.3 The Round Function • Rounds numeric data to specified number of decimal places. • Form: Round(number, decimal places) • Example: Dim dblNum As Double dblNum = 3.4567 lblAns.Caption = Round(dblNum, 2) ‘3.46 will be displayed

  8. Format Function • Used to format, or change the appearance of, numeric data. • Form: Format(number, “format type”) • Examples: lblAns.Caption = Format(8789, “General Number”) ‘8789 lblAns.Caption = Format(8789, “Currency”) ‘$8,789.00 lblAns.Caption = Format(8789, “Fixed”) ‘8789.00 lblAns.Caption = Format(8789, “Standard”) ‘8,789.00 lblAns.Caption = Format(89, “Percent”) ‘8900.00% lblAns.Caption = Format(1, “Yes/No”) ‘Yes lblAns.Caption = Format(0, “True/False”) ‘False lblAns.Caption = Format(1, “On/Off”) ‘On

  9. 8.5 Built-in Business Function • Three business Built-in function • Pmt(rate, term, principal) • PV(rate, term, payment) • FV(rate, term, investment)

  10. Pmt(rate, term, principal) Returns the periodic payment for an installment loan. Rate- is the interest rate per period Term – is the total number of payments to be made Principal – is the amount borrowed Example: Calculate the monthly payments on a 30 – year, $100,000 loan with an annual interest rate of 6%. dblPay = Pmt(0.06/12, 360, -100000) lblAns.Caption = Format(dblPay, “Currency”) ‘$599.55 ***Since payments are monthly, the interest rate must also be computed monthly by dividing the annual rate interest 6% by 12. ***The principal is negative because it is the amount borrowed.

  11. PV(rate, term, payment) Returns the present value of an investment. Rate- is the interest rate per period Term – is the total number of payments to be made Payment – amount invested per period Example: Determine the cost of financing a car. $250 per month over a 4 year period is applied to a loan with an interest rate of 8%. dblAmount = 250 * 12 * 4 ‘12000 dblPresent = PV(0.08/12, 48, -250) ‘10240.48 dblFin = dblAmount – dblPresent lblAns.Caption = Format(dblFin, “Currency”) ‘$1,759.52 ***This means that $1,759.52 is spent on Financing

  12. FV(rate, term, investment) Returns what a series of equal payments invested at a fixed interest will be worth after a period of time. Rate- is the interest rate per period Term – is the total number of payments to be made Investment – is the amount invested per period Example: You invest $500 per month in a retirement plan earning 8% interest per year. What would it be worth in 20 years. dblFuture = FV(0.08/12, 240, -500) lblAns.Caption = Format(dblFuture, “ Currency”) ‘$294,510.21

  13. List Boxes • Allows the user to select a value from a set of values. • Use the Icon to create a List Box Properties of a List Box • Name – use the prefix “lst” for the name • List – stores a group of strings that makes up the list. • Sorted – displays the item in the list in alphabetical order. (Design Time only) • Text – stores the selected list item. (Run Time Only) • ListCount – can be used at run time to determine number of items in the list.

  14. List Box • Click Event – is executed when the user clicks on an item in the list box. • AddItem Method – is used to add an item to the list • Example: lstControl.AddItem Item • lstControl – is the name of the list and item is a string object or string double quotes added to the list box • Clear – delete List Box contents of the list. • Example: lstControl.Clear

  15. Combo Boxes • Also called collapsible list • The icon is used to create it. • Properties: • Name – use the prefix “cbo” for the name • List – stores a group of strings that makes up the items in the combo box. • Sorted – displays the item in the combo box in alphabetical order. (Design Time only) • Text – stores the selected item in the combo box. (Run Time Only) • ListCount – can be used at run time to determine number of items in the combo box • Style – dropdown combo, simple combo, or dropdown list. Runtime use vbComboDropDown, vbComboSimple, or vbComboDrop-DownList.

  16. Combo Boxes • Click Event – is executed when the user clicks on an item in the combo box. • AddItem Method – is used to add an item to the list • Example: cboControl.AddItem Item • cboControl – is the name of the list and item is a string object or string double quotes added to the list • Clear – delete Combo Box contents of the list Example: cboControl.Clear

More Related