Micro Focus QTP (UFT) Forums

Full Version: How to count a repeated number in number in particular range
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a numbers 1,2,3,4.....98,99,100.
how to find how many times "1", or "2" number is present between 1 to 100 numbers
there could be an optimized way for this.
this is what i can have now, see the code below if it helps
Code:
msgbox RepeatedNumberCount(1,1000,"1")
Function RepeatedNumberCount(StartLimit,EndLimit,NumbertoSearch)
   RepeatedNumberCount = 0
   Dim sNum
    For Num = StartLimit to EndLimit
        sNum = cstr(Num)
        If instr(sNum,NumbertoSearch)  Then
            For n = 1 to Len(sNum)
                CurNum = Mid(sNum,n,1)
                If CurNum = NumbertoSearch Then nCount = nCount + 1
            Next
        End If
    Next
    RepeatedNumberCount = nCount
End Function