Call by Value
-
Upload
gretchen-torres -
Category
Documents
-
view
12 -
download
0
description
Transcript of 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!
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
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”
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
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