1 / 6

Parameter Passing in Visual Basic

Parameter Passing in Visual Basic. Computer Science 2 Gerb Objective: Understand parameter passing in Visual Basic. Parameters. Recall that parameters are the data we pass to procedures to help them do their job When a procedure takes parameters , we declare them Give them a type

lynda
Download Presentation

Parameter Passing in Visual Basic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Parameter Passing in Visual Basic Computer Science 2 Gerb Objective: Understand parameter passing in Visual Basic

  2. Parameters • Recall that parameters are the data we pass to procedures to help them do their job • When a procedure takes parameters, we declare them • Give them a type • Give them a name • Decide whether they are ByVal or ByRef (more on this later) • The parameters that a procedure is declared to accept are called formal parameters • The values passed to it when it is called are called actual parameters • Parameters are also called arguments

  3. Formal Parameter Example: Three formal parameters Sub TwoDigits(ByVal intNum As Integer, ByRef intFirstDigit As Integer, ByRef intSecondDigits As Integer) intFirstDigit=intNum/10 intSecondDigit=intNum Mod 10 End Sub

  4. The first is an integer, ByVal Sub TwoDigits(ByValintNum As Integer, ByRef intFirstDigit As Integer, ByRef intSecondDigits As Integer) intFirstDigit=intNum/10 intSecondDigit=intNum Mod 10 End Sub

  5. Second and third are ByRef integers Sub TwoDigits(ByVal intNum As Integer, ByRef intFirstDigit As Integer, ByRef intSecondDigits As Integer) intFirstDigit=intNum/10 intSecondDigit=intNum Mod 10 End Sub

  6. Difference between ByVal and ByRef • If we called our twodigits procedure: Call TwoDigits(i,j,k) • The value of i will not change • i is declared ByVal, • This means its value will not change when the procedure is called • j and k could change after the procedure finishes • j and k are ByRef • That means if the procedure changes the value of these parameters, they remain changed after the procedure finishes

More Related