Page 192 - Open Soource Technologies 304.indd
P. 192
Event Driven Programming
Object Property Setting
frmFirstName Text Extract First Name
lblName Text Name
txtFullName
btnDetermine Text Determine First Name
txtFirstName ReadOnly True
Private Sub btnDetermine_Click(...) Handles btnDetermine.Click
‘Determine a person’s first name
Dim name As String
name = txtFullName.Text
txtFirstname.Text = FirstName(name)
End Sub
function FirstName(ByVal name As String) As String
‘Extract the first name from a full name
Dim firstSpace As Integer
firstSpace = name.IndexOf(“ “)
Return name.Substring(0, firstSpace)
End function
[Run, type Thomas Woodrow Wilson into the text box, and then click the button.]
Write a program for Procedures in visual basic.
8.2 User-Defined Function Having Several Parameters
The input to a user-defined function can consist of one or more values. Two examples of function
with several parameters follow. One-letter variable names have been used so the mathematical
formulas will look familiar and be readable. Because the names are not descriptive, the meanings
of these variables are carefully spelled out in comment statements.
function Hypotenuse(ByVal a As Double, ByVal b As Double) As Double
‘Calculate the hypotenuse of a right triangle
186 LOVELY PROFESSIONAL UNIVERSITY