Micro Focus QTP (UFT) Forums
Random Number generator and verification problem - 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: Random Number generator and verification problem (/Thread-Random-Number-generator-and-verification-problem)



Random Number generator and verification problem - jinnah - 09-26-2012

In one of the fileds data needs to be between 10-99 and unique.
For now I am trying the following codes

Code:
Dim upperbound, lowerbound
upperbound=99  
lowerbound =10
For i=10 to 99  
CatEventCode=Int((upperbound - lowerbound + 1) * Rnd + lowerbound)  
Next[/b][/color]

[color=#800000][b]If Browser("...").Page("...").WebEdit("...").GetROProperty("value")=CatEventCode Then
    Reporter.ReportEvent micPass,"2 digits value is entered in <CAT/EvenetCode> field",""
    Call Logger(1," 2 digits value is entered in <CAT/EvenetCode> field")
    else
    Reporter.ReportEvent micFail,"2 digits value is not entered in <CAT/EvenetCode> field",""
    Call Logger(2,"2 digits value is not entered in <CAT/EvenetCode> field")
End If


Why does verification fail?

Any other idea for generating 2 digits unique number?


RE: Random Number generator and verification problem - Ankesh - 09-26-2012

Jinnah,

Can you explain why are you using For loop. There is absolutely no need of this loop. You need to use randomize keyword before creating the random number.

You can try any of the below options.
Code:
1.
intMaxValue=99
intMinValue=10

Randomize  'This will generate a unique number every time
            
intRndVariable= Int((intMaxValue-intMinValue+ 1) * Rnd +intMinValue)

2. Use RandomNumber function

intRandomNumber=RandomNumber(intLoweLimit,Upperlimit)

e.g., a=RandomNumber(10,99)

Regards,
Ankesh


RE: Random Number generator and verification problem - jinnah - 09-26-2012

Hi Anikesh I see you are the best one in this forum. I think you already know my qtp skill. I have started learning it and using in my job at the same time. I just googled it and used it(For loop). Anyway, I will use your one as those are more Logical.

Anyway, Anyidea how to verify if radom number is entered in the webedit box?


RE: Random Number generator and verification problem - Ankesh - 09-27-2012

I see the comparison code by you is fine, it requires a slight modification though.

Code:
If Browser("...").Page("...").WebEdit("...").GetROProperty("value")=CatEventCode Then

lets talk abt the above line.

CatEventCode : This the random number generated. This is in integer format.

Browser("...").Page("...").WebEdit("...").GetROProperty("value")= This will return the value in string format.

so if you directly compare the value, result will be fail. You need to do the typecasting.

correct code will be

Code:
strDisplayedValue=Browser("...").Page("...").WebEdit("...").GetROProperty("value") 'get the value
'convert it to integer for comparision
intConvertedValue=Cint(strDisplayedValue)
'now do the comparision
if intConvertedValue=CatEventCode Then
'Pass
Else
'Fail
End IF

Regards,
Ankesh


RE: Random Number generator and verification problem - jinnah - 09-28-2012

Waooo Man! I see I am learning. I don't know how long you will support me in thsi way. I am already in love of this site and ofcourse you!! Ha haa. Yes, I had problem with verification. I used same method you taught me for Reg Ex verification. I did.
-----------------------------------------------------------
Code:
upperbound=99  
lowerbound =10
CatEventCode=Int((upperbound - lowerbound + 1) * Rnd + lowerbound)  

        Browser("ClaimCenter_Br").Page("ClaimCenter_Pg").WebEdit("Cat/EvenetCode").Set CatEventCode
CatastrophyEventCode=Browser("ClaimCenter_Br").Page("ClaimCenter_Pg").WebEdit("Cat/EvenetCode").GetROProperty("value")

Set RegEx=CreateObject("VBScript.RegExp")
RegEx.Pattern="[0-9]+"
BllnResult=RegEx.Test(CatastrophyEventCode)

If BllnResult=True Then
    Reporter.ReportEvent micPass,"2 digits value is entered in <CAT/EvenetCode> field",""
    Call Logger(1," 2 digits value is entered in <CAT/EvenetCode> field")
    else
    Reporter.ReportEvent micFail,"2 digits value is not entered in <CAT/EvenetCode> field",""
    Call Logger(2,"2 digits value is not entered in <CAT/EvenetCode> field")
End If
Set RegEx=Nothing
------------------------------------------------------------

But I am going to replace these with your new codes.It is more logical and I ve just learned a new thing. Great buddy. Thanks again.


Hi, I am sorry as my reply goes on top of yours. I think I need to reply from Quick Reply section.

So to covert string to Intiger Cint is used. What about Intiger to string? Sorry for dumb question.

Yes bro! I have just changhed my previous codes. IT works fine. Thanks again

Here it is

Code:
upperbound=99  
lowerbound =10
CatEventCode=Int((upperbound - lowerbound + 1) * Rnd + lowerbound)  

        Browser("ClaimCenter_Br").Page("ClaimCenter_Pg").WebEdit("Cat/EvenetCode").Set CatEventCode
StrCatEventCode=Browser("ClaimCenter_Br").Page("ClaimCenter_Pg").WebEdit("Cat/EvenetCode").GetROProperty("value")

needs to be coverted to Intiger
IntCatEventCode=Cint(StrCatEventCode)
If  IntCatEventCode=CatEventCode Then
    Reporter.ReportEvent micPass,"2 digits value is entered in <CAT/EvenetCode> field",""
    Call Logger(1," 2 digits value is entered in <CAT/EvenetCode> field")
    else
    Reporter.ReportEvent micFail,"2 digits value is not entered in <CAT/EvenetCode> field",""
    Call Logger(2,"2 digits value is not entered in <CAT/EvenetCode> field")
End If