Procedures and Parameters
The learning objectives for this lab are:
In this lab we have two procedures. One provides concatenation functionality, while the other provides arithmetic addition functionality.
Program the application as directed by your TA.
After programming and debugging the project. Perform the following tests.
Key terms
Option Explicit
' This is a general procedure that concatenates two strings
' Note that the operation is applied to formal parameters
Private Sub ConcatenateTwoStrings(strOut As String, strFirst As String, strSecond As String)
strOut = strFirst & strSecond
End Sub
' This is a general procedure that adds two integers together
' Note that the operation is applied to formal parameters
Private Sub AddTwoIntegers(intOut As Integer, intFirst As Integer, intSecond As Integer)
intOut = intFirst + intSecond
End Sub
' This is an event procedure that declares actual parameters, sets the values of two input parameters
' to the contents of text boxes on the form, then passes these parameters to a general procedure.
' The output parameter of the general procedure is then used to set the caption property of a label
' so we can read it.
Private Sub cmdAdd_Click()
Dim intA As Integer
Dim intB As Integer
Dim intC As Integer
intA = txtFirst.Text
intB = txtSecond.Text
Call AddTwoIntegers(intC, intA, intB)
lblAdd.Caption = intC
End Sub
Private Sub cmdConcatenate_Click()
Dim strA As String
Dim strB As String
Dim strC As String
strA = txtFirst.Text
strB = txtSecond.Text
Call ConcatenateTwoStrings(strC, strA, strB)
lblConcatenate.Caption = strC
End Sub
Private Sub Form_Load()
' Format the labels when the form loads
lblConcatenate.Caption = ""
lblConcatenate.BackColor = vbRed
lblAdd.Caption = ""
lblAdd.BackColor = vbWhite
' Set the text in the input boxes to empty strings so we
' don't anything there when we start the program
txtFirst.Text = ""
txtSecond.Text = ""
End Sub