Login | |
|
 |
VBSCript For Begineers(Array) - 5/3/2007 4:54:56 PM
|
|
 |
|
| |
amitkumar.s
Posts: 2
Score: 0
Joined: 5/3/2007
Status: offline
|
Public Function CompareArrays(ExpArray, ActArray, Test_step) iResult=True If (UBound(ExpArray)<>UBound(ActArray)) Then call Logger(Test_step,"Array comparision failed as the Sizes of Arrays are not equal","Fail") Else array_size=UBound(ExpArray) End If For i=0 to array_size If (LCase(Trim(ExpArray(i)))<>LCase(Trim(ActArray(i))))Then iResult=False Else iResult=True End If Next End Function Public Function CompareinArray(ExpArray, ActArray, Test_step) array_size=UBound(ExpArray) For i=0 to array_size iResult=False For j=0 to UBound(ActArray) If (LCase(Trim(ExpArray(i)))=LCase(Trim(ActArray(j))))Then iResult=True Exit For End If Next If NOT iResult Then iResult=False End If Next End Function Public Function CompareValueinArray(StringVal, ExpArray, Test_step) iResult=False array_size=UBound(ExpArray) For i=0 to array_size If (LCase(Trim(ExpArray(i)))=LCase(Trim(StringVal)))Then iResult=True End If Next If iResult Then CompareValueinArray=True Else CompareValueinArray=False End If End Function Public Function Join_Arrays(Array1, Array2, Joined_Array) ReDim Joined_Array(Ubound(Array1)+Ubound(Array2)+1) For ind=0 to Ubound(Array1) Joined_Array(ind)=Array1(ind) Next For ind=0 to Ubound(Array2) Joined_Array(Ubound(Array1)+1+ind)=Array2(ind) Next End Function Public Function ArraySort_desc(arrShort) For i = UBound(arrShort) - 1 To 0 Step -1 For j= 0 to i If arrShort(j) < arrShort(j+1) then temp=arrShort(j+1) arrShort(j+1)=arrShort(j) arrShort(j)=temp end if next Next End Function Public Function ArraySort_asc(arrShort) For i = UBound(arrShort) - 1 To 0 Step -1 for j= 0 to i if arrShort(j) > arrShort(j+1) then temp=arrShort(j+1) arrShort(j+1)=arrShort(j) arrShort(j)=temp end if next Next End Function
|
|
| |
|
|
|
 |
RE: VBSCript For Begineers(Array) - 5/4/2007 1:55:05 AM
|
|
 |
|
| |
ebgreen
Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
|
Thanks for sharing your code. Some comments: Public Function CompareArrays(ExpArray, ActArray, Test_step) iResult=True If (UBound(ExpArray)<>UBound(ActArray)) Then call Logger(Test_step,"Array comparision failed as the Sizes of Arrays are not equal","Fail") Else array_size=UBound(ExpArray) End If For i=0 to array_size If (LCase(Trim(ExpArray(i)))<>LCase(Trim(ActArray(i))))Then iResult=False Else iResult=True End If Next End Function iResult=True is misleading. You name the variable with a name that indiocates that it will be an integer yet you use it like a boolean. call Logger(Test_step,"Array comparision failed as the Sizes of Arrays are not equal","Fail") - There is no Logger function provided The logic of the function is faulty. The way it is written, it will return true anytime that the last elements of the array are equal and the arrays are the same size regardless of whether all the rest of the elements are equal. The Test_Step parameter is never used so there really isn't any point to passing it into the function. The function never returns a result. Public Function CompareinArray(ExpArray, ActArray, Test_step) array_size=UBound(ExpArray) For i=0 to array_size iResult=False For j=0 to UBound(ActArray) If (LCase(Trim(ExpArray(i)))=LCase(Trim(ActArray(j))))Then iResult=True Exit For End If Next If Not iResult Then iResult=False End If Next End Function If you move iResult=False out of the For loop at the beginning then there is no need for the If Not iResult Then logic block any more. The Test_Step parameter is never used so there really isn't any point to passing it into the function. This function doesn't actually return any result. Public Function CompareValueinArray(StringVal, ExpArray, Test_step) iResult=False array_size=UBound(ExpArray) For i=0 to array_size If (LCase(Trim(ExpArray(i)))=LCase(Trim(StringVal)))Then iResult=True End If Next If iResult Then CompareValueinArray=True Else CompareValueinArray=False End If End Function The Test_Step parameter is never used so there isn't really any point to passing it into the function. The If iResult Then block is pointless. All you need to do is CompareValueInArray = iResult. Neither of the sort functions actually sort the array.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|