08-04-2009, 10:59 AM
Yes you are right venkat, the function will validate only in between 1 and 2, 2 and 3 and so on. but the function is designed in the same way only that if the first comparison fails then it determines that the array is not in order. say n(1) = 5, n(2) = 6, n(3) = 4 then as statement in the function
if n(1) > n(2) then ie 5 > 6 (will return false)
and conciders the two is in order again
if n(2) >n(3) ie 6 > 4 (will return true)
which is not in order and so the function will return false
and it can be determined that the array is not in ascending order.
As per my knowledge, I dont think the logic is wrong anywhere, let me know if I am wrong somewhere.
Regarding time, I think the way you have written statement is causing the issue. the function call 'IsAscending (n)' should be out of the for loop. Idea is first get all the cell values into array then compare.
Code:
If n(i) > n(i+1) Then
'Return value of IsAscending
IsAscending = false
exit for
End If
and conciders the two is in order again
if n(2) >n(3) ie 6 > 4 (will return true)
which is not in order and so the function will return false
and it can be determined that the array is not in ascending order.
As per my knowledge, I dont think the logic is wrong anywhere, let me know if I am wrong somewhere.
Regarding time, I think the way you have written statement is causing the issue. the function call 'IsAscending (n)' should be out of the for loop. Idea is first get all the cell values into array then compare.