' ' File: SomethingArray.vbs (Based on bubble sort) ' Author: Kelvin Sung ' ' ' ' Questions: for the following vbs code ' ' 1. How many times will you call ALotOfWork? ' Ans: pass=0, 1, 2 so 3 times ' ' 2. What is the output of this program ' ' Something like this should take you about 20-30 minutes ' ' ***************************************************************************************** Option Explicit Dim MyArray MyArray = Array(10, 1, 4, 6) WhatAmIDoing MyArray PrintOneArray MyArray, "Array" ' ***************************************************************************************** ' Sub WhyThis(ByRef myA(), ByVal i) Dim temp temp = myA(i) myA(i) = myA(i+1) myA(i+1) = temp MsgBox "index=" & i & " a=" & myA(i) & " b=" & myA(i+1) End Sub Sub ALotOfWork(ByRef yourA()) Dim index For index = 0 To UBound(yourA)-1 If (yourA(index) > yourA(index+1)) Then WhyThis yourA, index End If Next End Sub Sub WhatAmIDoing(ByRef anArray()) Dim pass For pass = 0 To UBound(anArray)-1 ALotOfWork anArray Next End Sub ' **************************************************************************************************** ' **************************************************************************************************** ' Sub Name: PrintOneArray(ByRef myArray, ByRef label) ' Descriptions: This function call takes in 2 input parameter. And it will prints ' the entire contents of the array in message box ' ' Source code from: PrintOneArray.vbs ' ' Input Parameters: ByRef myArray, ByRef label ' 1) myArray -- the input array ' 2) label -- label to message box ' Returns Value: NONE ' Possible Errors: NONE ' Start of Sub PrintOneArray() Sub PrintOneArray(ByRef myArray, ByRef label) Dim msg, index For index = 0 to UBound(myArray) ' loop to upper bound msg = msg & "Array(" & index & ") = " & myArray(index) & vbCrLf ' get array values Next msg = msg & "Array Upper Bound is: " & UBound(myArray) & vbCrLf ' get upper bound value msg = msg & "Array Lower Bound is: " & LBound(myArray) & vbCrLf ' lower bound value MsgBox msg, ,label ' display messsage box End Sub ' End of Sub PrintOneArray() ' **************************************************************************************************** ' ****************************************************************************************************