Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort.

Similar presentations


Presentation on theme: "CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort."— Presentation transcript:

1 CSC 162 Visual Basic I Programming

2 Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort

3 Array Parameters When arrays are passed to procedures, they must be passed ByRef. –Visual Basic makes this a requirement since copying large arrays could take up too much room in memory.

4 Array Parameters Array parameters are not specified with a size, since they are passed ByRef. Private Sub PrintNums(ByRef intNums() As Integer) Dim intCounter As Integer For intCounter = LBound(intNums) To UBound(intNums) Print intNums(intCounter) Next intCounter End Sub

5 Array Parameters When arrays are passed into a procedure, the size is also not specified, since they are passed ByRef. Dim intValues(1 To 100) As Integer. Call PrintNums(intValues())

6 Array Parameters However, individual elements of the array are passed just like any single value. Private Sub PrintValue(ByVal intValue As Integer) Print "The selected value is " & intValue End Sub Dim intNumbers(1 To 50) As Integer. Call PrintValue(intNumbers(20))

7 Bubble Sort Arrays can be sorted in two ways: –Ascending (1  100, A  Z, etc.) –Descending (100  1, Z  A, etc.) Array functions: –Starting index (lower bound): LBound() –Ending index (upper bound): UBound()

8 Lab Assignment Write a program that will do the following: 1.Put 20 random (integer) numbers with a range of 1 to 100 into an array of size 20. 2.Sort the array in descending order.* 3.Display the entire sorted array in a ListBox. * Use the Bubble Sort algorithm, but put it into a sub procedure called DescendingSort. Programming Assignment 5 Due Monday, November 10 / Tuesday, November 11 Page 241 #6.18 Page 241 #6.19


Download ppt "CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort."

Similar presentations


Ads by Google