Micro Focus QTP (UFT) Forums
VB Script - random string - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: VB Script - random string (/Thread-VB-Script-random-string)



VB Script - random string - qtp_user22 - 01-31-2010

hello,

I need VB Script (function ) for random string

please Help me Smile


RE: VB Script - random string - qtp_user22 - 02-01-2010

I have This :

Code:
Function RandomString
    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


but it does not work


RE: VB Script - random string - Saket - 02-01-2010

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



RE: VB Script - random string - rajvanan - 02-01-2010

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.


RE: VB Script - random string - gaveyom - 09-29-2011

Hi Friend,

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

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

Code:
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


RE: VB Script - random string - roysam404 - 06-19-2014

Try the below code. It ran successfully for me

Code:
Dim str

Const LETTERS = "abcdefghijklmnopqrstuvwxyz0123456789"
    
    strLen=len(LETTERS)

    For i = 1 to strLen

        str = str & Mid( LETTERS, RandomNumber( 1, Len( LETTERS ) ), 1 )

    Next

    RandomString = str
    msgbox str

Thanks,
Samir