QTP Forums

Full Version: VB Script - random string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello,

I need VB Script (function ) for random string

please Help me Smile
I have This :

PHP Code:
Function RandomString
    Dim str
    
Const LETTERS "abcdefghijklmnopqrstuvwxyz0123456789" 
    
For 1 to strLen
        str 
str MidLETTERSRandomNumber1LenLETTERS ) ), )
    
Next
    RandomString 
str

DataTable
.Value("rndstr"dtGlobalSheet) = str

End 
Function 


but it does not work
hey qtp_user22,

you have missed to put the parameter strLen
use this
Code:
Function RandomString( ByVal strLen )
    Dim str
    Const LETTERS = "abcdefghijklmnopqrstuvwxyz0123456789"
    For i = 1 to strLen
        str = str & Mid( LETTERS, RandomNumber( 1, Len( LETTERS ) ), 1 )
    Next
    RandomString = str

DataTable.Value("rndstr", dtGlobalSheet) = str

End Function
Hi,
The simplest way is to use "AUT"& RandomNumber().

There is a random number generator facility provided in QTP itself. And u can very well use it.
U can give the range of numbers , like Between 1 to 10,000 and the number will be generated itself in the given range. Each time its a different number between the given range.

IT can find in the help section in the Qtp help.

Try, and let me know if u are not able to.
Hi Friend,

hope this will help for you, try this and let me know if it not works

******************************************************

MsgBox RandomString
Function RandomString
Dim str
Const LETTERS = "abcdefghijklmnopqrstuvwxyz0123456789"
For i = 1 to len(LETTERS)
str = str & Mid( LETTERS, RandomNumber( 1, Len( LETTERS ) ), 1 )
Next
RandomString = str

DataTable.Value("rndstr", dtGlobalSheet) = str

End Function

******************************************************


Thanks & Regards,
G@veyom
Reference URL's