








































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
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