Micro Focus QTP (UFT) Forums
Random Email & User Name - 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 Email & User Name (/Thread-Random-Email-User-Name)



Random Email & User Name - vbkurutza - 04-16-2008

Hello there, I am very new to the product (QTP 9.2) after using Empirix eTester for the past few years. Anyway, I am running some scripts where I need a unique and random user name (any alpha-num value > 5 chars) and email address. I can't seem to find anything in the help on how to do this. Any ideas??


RE: Random Email & User Name - niranjan - 04-16-2008

There are several ways you can write a function for this...


There are several ways to write function for this....

' If you just want to generate a random string..use this
Code:
FUNCTION GetRandomString(LEN)  
Dim intI, StrS  
Const StartChr ="a", Range = 26  
   Randomize  
   StrS = ""  
   FOR intI = 0 TO LEN-1    
     StrS = StrS + Chr(asc(StartChr) + Rnd() * Range )    
   NEXT  
   GetRandomString = StrS  
END FUNCTION


Now you can use the above function and tweak it according to your objective
Example:for email
Code:
Dim StrE, StrE1, StrE2, StrE3, StrE4, StrEmail
StrE = Call GetRandomString(10)
StrE1 = "@"
StrE2 = Call GetRandomString(5)
StrE3 = "."
StrE4 = Call GetRandomString(5)
StrEmail = StrE&StrE1&StrE2&StrE3&StrE4



RE: Random Email & User Name - newqtp - 04-16-2008

Hi Niranjan

I've made couple of function when i call them using like
'let take an example adding two no
Code:
function getsum(a,b)
sum = a+b
end function
var = call getsum(2,3) ' throw a error here.
msgbox var
it throws error says syntax error same with your function too when you run your above script.
can you plz help where i'm doing wronge.

thanks.


RE: Random Email & User Name - niranjan - 04-17-2008

Hi,

Right, it should throw error.
If you want to get the return value from a function you need to assign it to function name.
Example: In your case, instead of sum = a+ b USE getsum = a + b. It will work!!


RE: Random Email & User Name - newqtp - 04-18-2008

Hi Niranjan ,
Thanks for the reply.But I still have doubt on that. In code you have used the variable.It's also throwing the same error as i'm getting in my.

Code:
FUNCTION GetRandomString(LEN) 'you have defined function here
Dim intI, StrS
Const StartChr ="a", Range = 26
Randomize
StrS = ""
FOR intI = 0 TO LEN-1
StrS = StrS + Chr(asc(StartChr) + Rnd() * Range )
NEXT
GetRandomString = StrS
END FUNCTION


Code:
Dim StrE, StrE1, StrE2, StrE3, StrE4, StrEmail
StrE = Call GetRandomString(10)
'here you are calling by using variable.
I'm getting error in your code too same as i'm getting in mine.

-Thanks.


RE: Random Email & User Name - niranjan - 04-18-2008

Thanks for pointing it out. Its my mistake.

Try this...
StrE = GetRandomString(10)


RE: Random Email & User Name - vbkurutza - 05-13-2008

Sorry guys but this is still not working - any more ideas?


RE: Random Email & User Name - niranjan - 05-14-2008

Whats the Error you are getting...