Call by Value

5
Call by Value =PVNRT(“R”,C11,C13,C13,C14) Function PVNRT(SolveFor, v1,v2,v3,v4) …….. PVNRT = v1*v2/ (v3*v4) End Function But what happen if you put a statement like: v4 = v3/v2 in your code. Does Cell C14 change????? By default, argument are “Call by Value, which means the values are placed in the argument list and not replaced upon return -- The arrows are one way signs!

description

Call by Value. =PVNRT(“R”,C11,C13,C13,C14). Function PVNRT(SolveFor, v1,v2,v3,v4). ……. PVNRT = v1*v2/ (v3*v4) End Function. But what happen if you put a statement like: v4 = v3/v2 in your code. Does Cell C14 change?????. - PowerPoint PPT Presentation

Transcript of Call by Value

Page 1: Call by Value

Call by Value

=PVNRT(“R”,C11,C13,C13,C14)

Function PVNRT(SolveFor, v1,v2,v3,v4)

……..

PVNRT = v1*v2/ (v3*v4)End Function

But what happen if you put a statement like: v4 = v3/v2 in your code. Does Cell C14 change?????

By default, argument are “Call by Value, which means the values are placed in the argument list and not replaced upon return -- The arrows are one way signs!

Page 2: Call by Value

Scope and Lifetime

Scope: What functions / subs can get the value of a variable.

Lifetime: How long does a variable have a value?

Will discuss this briefly, but will not dwell on it

Page 3: Call by Value

Module 1

DeclarationsDim x as singleDim y as singleFunction One (a,b,c)…..x = a*by=a/cOne = x/yEnd Function

Sub Two (a, b, c)Dim p as singleDim q as singlex=2*y+a/c+b…….End Sub

Points to Ponder:

x & y are declared in the Declarations section, thus they are available to all subs/functions in Module 1.

p & q are declared only in Sub Two, so their values are only available in Sub Two.

When Sub Two is finished, the values of p & q “disappear”

When Module 1 is exited, the values of x & y “disappear”

Page 4: Call by Value

Module2

DeclarationsDim x as singleDim y as singleFunction Onea (a,b,c)…..Onea = y/xEnd Function

Sub Twoa (a, b, c)…….End Sub

Module1

DeclarationsDim x as singleDim y as singleFunction One (a,b,c)…..One = x/yEnd Function

Sub Two (a, b, c)Dim p as singleDim q as single…….End Sub

Module1 does not “know” anything about Module2 and vice versa

Page 5: Call by Value

Buttons / Forms / And other Cool Stuff

Used to “Dress Up” an application

Used to interact with the user

Available from the IDE and from the Excel toolbar

Will look at only a few items