Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random Email & User Name
#1
Not Solved
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??
Reply
#2
Not Solved
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
Reply
#3
Not Solved
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.
Reply
#4
Not Solved
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!!
Reply
#5
Not Solved
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.
Reply
#6
Not Solved
Thanks for pointing it out. Its my mistake.

Try this...
StrE = GetRandomString(10)
Reply
#7
Not Solved
Sorry guys but this is still not working - any more ideas?
Reply
#8
Not Solved
Whats the Error you are getting...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Send automatic email notification when test run started helmzshelmz 0 1,125 04-03-2020, 07:54 AM
Last Post: helmzshelmz
  How to get input from the user in QTP? shanthiK 10 18,643 08-07-2017, 11:34 PM
Last Post: zunebuggy
  How to attach HTML file to Email Naresh 0 3,091 04-06-2015, 02:04 PM
Last Post: Naresh
  Create a random number starting with an alphabet QTPmate 4 4,298 07-31-2014, 09:29 AM
Last Post: QTPmate
  Help getting Sender Name from Email nidhitaneja 0 2,104 06-15-2014, 09:03 AM
Last Post: nidhitaneja

Forum Jump:


Users browsing this thread: 1 Guest(s)