51. Passing Arrays as Parameters - Visual Basic 2017

preview_player
Показать описание
Passing Arrays as Parameters- (See Description for Procedure and source code)

It’s extremely useful to be able to pass an array (which could be a list of values) to a function as a parameter.

In this Try It Out, you’ll look at how to pass an array to a function as a parameter.

1. Return to the Forms Designer in the Array Demo project (Tutorial 50) and add another Button control. Set its
Name property to btnArraysAsParameters and its Text property to Arrays as Parameters.

2. Double‐click the button and add the following bolded code to its Click event handler. You’ll receive an error message that the AddItemsToList procedure is not defined. You can ignore this error because you’ll be adding that procedure in the next step:

Private Sub btnArraysAsParameters_Click(sender As Object,
e As EventArgs) Handles btnArraysAsParameters.Click
'Clear the list
ClearList()
'List your friends
AddItemsToList(strFriends)
End Sub

3. Add the AddItemsToList procedure as follows:

Private Sub AddItemsToList(ByVal arrayList As String())
'Enumerate the array
For Each strName As String In arrayList
'Add the array item to the list
lstFriends.Items.Add(strName)
Next
End Sub

4. Run the project and click the button.

Please share and Subscribe for Updates.

Source: Beginning Visual Basic 2015 by Bryan Newsome
Рекомендации по теме
Комментарии
Автор

What is the name of the program that reads English speech?

mariyantsvetkov