70 likes | 229 Views
Document Procedure Relationship in OED. VB Nomenclature for Procedures. Procedures. Procedures perform a set of processes Defining procedures Private Sub ProcedureName(argument list with types) {body of procedure End Sub Calling procedures Call ProcedureName(arg1, arg2, …, argLast)
E N D
Procedures • Procedures perform a set of processes • Defining procedures • Private Sub ProcedureName(argument list with types) • {body of procedure • End Sub • Calling procedures • Call ProcedureName(arg1, arg2, …, argLast) • ProcedureName arg1, agr2, …, argLast • Arguments may be sent ByVal or ByRef • If not specified, ByRef is assumed
Functions • Functions calculate and return a single value • Defining functions Private Function FcnName(arg list with types) As FcnType {body of function{at least one line should assign {value to FcnName{NOTE: if nothing is assigned to FcnName, {the default value of FcnType is returned End Function
Functions • Calling functions • When the return value is used, the function name can appear anywhere an expression can appear variable = FcnName(arg1, arg2, …, argLast) • When the return value is discarded, a function may be called using the same syntax as for a procedure • Arguments may be sent ByVal or ByRef • If not specified, ByRef is assumed
ByVal A copy of the argument is made. Pros Generally safer than passing by reference. Cons Generally less efficient because of all the memory copying. Doesn't do parameter type checking. ByRef Both procedures reference the same memory location. Pros. Is generally more efficient than pass by value. Does parameter type checking. Cons Not as programmer "safe" as pass by value. Argument Passing
There is a syntactical difference between declaring or defining a function and a procedure. Both functions and procedures can accept multiple arguments ByVal or ByRef. Functions always return a value, but the value can be discarded. Functions exist for calling syntax reasons The manner by which they are commonly called serves as a reminder that they represent a single value (the result of the function) You can achieve the same result by using general procedures and returning the single result found through passing by reference – (but not generally desired). Procedures vs. Functions