








































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A lecture note from the university of pittsburgh's cs4 - introduction to programming course, held during the summer 2009 semester. The notes cover the topics of sub procedures and function procedures in visual basic. Sub procedures perform related tasks and can call other sub procedures, while function procedures always return one value. Examples and explanations of passing arguments and parameters, as well as the differences between sub procedures and function procedures.
Typology: Study notes
1 / 48
This page cannot be seen from the preview
Don't miss anything!









































7/8/09 CS4 - Summer 2009 - Lecture 10 1
Sub ProcedureName() statements End Sub
Sub ExplainPurpose()
lstBox.Items.Clear() ExplainPurpose() lstBox.Items.Add("") lstBox.Items.Add("Program displays a sentence") lstBox.Items.Add("identifying a sum.") End Sub
Sub Sum(ByVal num1 As Double, ByVal num2 As Double) arguments parameters displayed automatically
ExplainPurpose() Sum(2, 3) Sum(4, 6) Sum(7, 8) Output: Program displays a sentence identifying a sum. The sum of 2 and 3 is 5. The sum of 4 and 6 is 10 The sum of 7 and 8 is 15.
Variables and Expressions as Arguments Dim s As String = "CA" Dim p As Double = 19 Demo(s, 2 * p) Sub Demo(ByVal state As String, ByVal pop As Double) txtBox.Text = state & " has population " & pop & _ " million." End Sub
A Sub procedure can call another Sub procedure. Private Sub btnAdd_Click(...) Handles btnAdd.Click Sum(2, 3) End Sub Sub Sum(ByVal num1 As Double, ByVal num2 As Double) DisplayPurpose() lstBox.Items.Add("The sum of " & num1 & " and " _ & num2 & " is " & (num1 + num2) & "." End Sub
Public Sub btnOne_Click (...) Handles _ btnOne.Click Dim num As Double = 4 Triple(num) txtBox.Text = CStr(num) End Sub Sub Triple(ByVal num As Double) num = 3 * num End Sub Output: 4