Micro Focus QTP (UFT) Forums
How to count a repeated number in number in particular range - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: How to count a repeated number in number in particular range (/Thread-How-to-count-a-repeated-number-in-number-in-particular-range)



How to count a repeated number in number in particular range - gollsrin - 04-28-2011

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


RE: How to count a repeated number in number in particular range - Saket - 04-28-2011

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