Wednesday, March 6, 2013

How to delete duplicate values in an array

The following script works both for integers and straing arrays.

Rather than using two many for loops and complex logic, it can be done with Dictionary and another Array object.

dim tempArr()
'arrName=Array(5,5,5,5,12,10,15,10,125,5,1,1,2,3,4,5,6,7,8,8,8,8,8,8,8)
arrName=Array("uday","naveen","kiran","usha","uday","vani","usha")
set d=createobject("Scripting.Dictionary")
n=0
For i = 0 To UBound(arrName)
        If Not d.Exists(arrName(i)) Then
     redim preserve tempArr(n)
            d.Add arrName(i), arrName(i)
            tempArr(n) = arrName(i)
     n = n + 1
        End If
Next
arrName = tempArr
for i=0 to ubound(arrName)
 msgbox arrName(i)
next

Sunday, February 10, 2013

Find the sum of the digits till the sum reaches to a single digit


no=54563 'You can give any number you want

While no>0
    modValue=no mod 10
    result=result+modValue
    no=int(no/10)
    If no=0 and result >9 Then
        no=result
        result=0
    End If
Wend
print result