Visual Basic Programming II Lecture 6 - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Visual Basic Programming II Lecture 6

Description:

PPmt(rate, per, nper, pv, fv) How much principle is paid for a specific period? ... Homework #7 is due prior to the start of class. Following Class ... – PowerPoint PPT presentation

Number of Views:82
Avg rating:3.0/5.0
Slides: 13
Provided by: larrylan
Category:

less

Transcript and Presenter's Notes

Title: Visual Basic Programming II Lecture 6


1
Visual Basic Programming IILecture 6
  • MIS233
  • Instructor Larry Langellier

2
This Week Numeric Functions
  • How functions work
  • Writing your own functions
  • Using Built-in functions
  • Numeric conversion
  • Mathematical
  • Random Number generation
  • Financial

3
Numeric Functions
  • A Function is like a Procedure except it returns
    a value
  • Basic Syntax
  • PublicPrivate Function name (arg-list) As
    type
  • function statements
  • End Function
  • Example
  • Public Function Volume(Length, Width, _
  • Height) As Double
  • Volume Length Width Height
  • End Function
  • Assign a value () to the function name to return
    the value

4
Calling the Function
  • Calling a Function is similar to calling a
    Procedure, except since the function returns a
    value you must store the return value in a
    variable
  • Examples
  • Dim dblBoxVolume As Double
  • dblBoxVolume Volume (4, 5, 6)
  • lblVolume.Caption Volume (2, 4, 6)

5
Common Mistakes
  • Not assigning a return value inside the function
  • Not storing the return value to a variable when
    you call the function
  • Not separating argument values with commas
  • lblVolume.Caption Volume (3 5 7)
  • Defining the function with the keyword Sub

6
Writing Numeric Function Procedures
  • Visual Basic contains a number of built-in
    numeric functions which well see in a little
    bit
  • You will also want to write your own numeric
    functions on numerous occasions
  • Examples
  • 16.1 Convert Race Results
  • 16.2 Returning the Highest/Lowest Values

7
Built-In NumericConversion Functions
  • Int(number)
  • removes the fractional part of number, returns
    the next lower number for negatives
  • Fix(number)
  • removes the fractional part of number
  • Round(expression , numdecs )
  • rounds the expression to the specified number of
    decimals (0 is the default)
  • CInt(expression), CLng(expression),
    CSng(expression), CDbl(expression),
    CCur(expression), CStr(expression),
    CVar(expression)
  • Converts expression to the specified data type

8
Built-In Mathematical Functions
  • Exp(number) Atn(angle)
  • raises e to a power - arctangent of an
    angle
  • Log(number) Sin(angle)
  • computes the natural log - sine of an angle
  • Sqr(number) Cos(angle)
  • the square root - cosine of an angle
  • Abs(number) Tan(angle)
  • the absolute value - tangent of an angle
  • Sgn(number)
  • the sign of number
  • Example 16.3

9
Generating Random Numbers
  • Randomize( )
  • Seeds the random number generator
  • Rnd (number)
  • lt 0, The same value every time
  • gt 0, The next random number value (the default)
  • 0, The value most recently generated
  • Returns a value between 0 and 0.999999
  • Example
  • an integer between 1 and 6
  • Int((Rnd 6) 1)
  • Examples 16.4 and 16.5

10
Financial Functions - Annuities
  • Used when working with Interest and its effect
    on the value of money lets look these up in
    the Help System
  • FV(rate, nper, pmt, pv)
  • What will the future value be?
  • IPmt(rate, per, nper, pv)
  • How much interest is paid/received for a specific
    period?
  • NPer(rate, pmt, pv, fv)
  • How many payment periods will be required?
  • Pmt(rate, nper, pv, fv)
  • How much should the payment be per period?
  • PPmt(rate, per, nper, pv, fv)
  • How much principle is paid for a specific period?
  • Rate(nper, pmt, pv, fv)
  • What interest rate will yield the desired results?

11
Financial Functions Cash Flow
  • Computations related to cash flow a series of
    payments and receipts
  • NPV(rate, values())
  • Net Present Value
  • PV(rate, nper, pmt, fv)
  • Present Value
  • IRR(values())
  • Internal Rate of Return
  • MIRR(values(), finance_rate, reinvest_rate)
  • Modified Rate of Return
  • Example 16.6

12
Details
  • Next Class
  • Read Chapter 17 String Functions
  • Homework 7 is due prior to the start of class
  • Following Class
  • The Midterm Project will be due at the beginning
    of class
Write a Comment
User Comments (0)
About PowerShow.com