Popular in Course
Popular in ComputerScienence
This 0 page Class Notes was uploaded by Ms. Bridie Kohler on Sunday November 1, 2015. The Class Notes belongs to CS 1103 at Oklahoma State University taught by Staff in Fall. Since its upload, it has received 10 views. For similar materials see /class/232848/cs-1103-oklahoma-state-university in ComputerScienence at Oklahoma State University.
Reviews for CS 1103
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 11/01/15
Parameter Passing The names in parentheses in a Private Sub or Private Function statement are called parameters For example x and y are parameters in the statement Private Sub PP1x As Integer y As Integer The items in parentheses in a Call statement or in a function invocation statement cc Funcl below are called arguments Arguments may be variables literal constants named constants or expressions In the two statements just below aa 37 bb2 and Hello are arguments aa is a variable 37 and Hello are literal constants and bb2 is an expression Call PP2aa 37 cc Func1bb 2 aa quotHelloquot Parameters and arguments are matched by position not by name rst parameter lt gt rst argument second parameter lt gt second argument The name of an argument variable may be the same as the name of the corresponding parameter but it doesn t have to be They must have the same type however with only one exception to be covered below If an argument is a variable it is usually passed see below to the subprogram by reference or equivalently by address No new copy of the variable is made for use in the subprogram the subprogram is told where to nd the argument variable If the value of the parameter is changed the value of the corresponding argument variable is changed immediately Therefore an argument variable passed by reference can be used to send information into a subprogram or to receive information back from the subprogram or both The purpose of call by reference is to allow a called subprogram to send information back to the calling subprogram Under certain circumstances an argument is passed to a subprogram by value This happens if 1 the argument is a literal constant a named constant or an expression or 2 the argument is a variable enclosed in an extra set of parentheses see Comment 5 on page 129 or 3 the corresponding parameter is declared to be passed ByVal Private Sub PP3 uu As Integer ByVal WW As String When an argument is passed by value a new local copy of this argument is created in the called subprogram at the time the Call statement is executed The corresponding parameter can be used tested or changed but no new information is ever passed back to the calling subprogram through this argument When the program returns from the called subprogram the local copy is destroyed Value arguments are used to carry information into a subprogram only The purpose of call by value is to protect an argument from being changed when the programmer does not want it to be changed Variables andor named constants can be declared at form level before the rst Private Sub or Private Function We have already done this with named constants the author does it with array variables in chapter 4 Form level is also called global The names of formlevel quantities can be declared locally in a Private subprogram If this is done the formlevel quantities are ignored and the local name declared in the local Dim is used inside that subprogram Declare a form level named constant maxVal This might normally be spelled MAXVAL Const maxVal As Integer 20 Private Sub PP4 picBoxPrint maxVal The value of the form level named constant 20 was printed here End Sub Private Sub PP5 Dim maxVal As Integer In this subprogram maxVal is a local variable not the form level Const maxVal 50 picBoxPrint maxVal End Sub The general scope rule is that names declared using Dim or Const in a Private subprogram cannot be seen from outside of that subprogram for example from within another Private subprogram but formlevel names can be seen from inside of a Private subprogram if those names were not declared as parameters named constants or variables in that subprogram Whenever a name is used in a Private subprogram Visual Basic rst looks to see if that name was declared inside that subprogram using Const or Dim If it was then that declaration is used for that name If it wasn t then VB looks for the name at form level The rule followed by VB is Look in this subprogram rst If not found here look outside 24 September 2003
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'