CSC 162 Visual Basic I Programming
Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort
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.
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
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())
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))
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()
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 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