Micro Focus QTP (UFT) Forums
Count the number of 3 number appers between 0-3333 - 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Count the number of 3 number appers between 0-3333 (/Thread-Count-the-number-of-3-number-appers-between-0-3333)



Count the number of 3 number appers between 0-3333 - SaranKumarV - 09-17-2010

Hi,

Could some one please tell me how to count occurence of 3digit between 3 and 3333.
I tried with the following code I am getting the numbers which contain 3 in the number but problem comes when there is number like (3000) which prints 4 times since length of the number (3000) is 4.

Code:
For i=3 to 3333
temp=i
While temp>0
  d=instr(temp,3)
  If (d <> 0) Then
     c = c+1
     print(i)
  End If
temp = temp/10
temp = Fix(temp)
Wend
Next
Print(c)



RE: Count the number of 3 number appers between 0-3333 - rdemers25 - 09-20-2010

Why wouldn't you try this? If the answer is 1336, then this works.

Code:
for i = 1 to 3333
    for j = 1 to len(Cstr(i))
        if Asc(Mid(CStr(i),j,1)) = 51 Then
        iCnt = iCnt+1
        End If
    Next
Next