Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB Script - random string
#1
Solved: 9 Years, 9 Months, 4 Weeks ago
hello,

I need VB Script (function ) for random string

please Help me Smile
Reply
#2
Solved: 9 Years, 9 Months, 4 Weeks ago
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
Reply
#3
Solved: 9 Years, 9 Months, 4 Weeks ago
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

Reply
#4
Solved: 9 Years, 9 Months, 4 Weeks ago
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.
Reply
#5
Solved: 9 Years, 9 Months, 4 Weeks ago
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
Reply
#6
Solved: 9 Years, 9 Months, 4 Weeks ago
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  VB Script:number of times a character appears in a string with position Jyobtech 1 11,691 08-07-2013, 01:03 PM
Last Post: anil2u
  How to have a variable that has a string comma string .. shareq1310 5 4,764 11-09-2011, 03:33 PM
Last Post: parminderdhiman84
  How to select a option based on Random Q/A zerocool 1 2,855 09-16-2011, 04:57 AM
Last Post: vIns
  Copying random length part of the string. unbeliever 5 4,468 01-07-2010, 02:55 PM
Last Post: unbeliever
  string function to get a letter from a string ajay.r1982 3 7,340 06-30-2009, 08:58 PM
Last Post: Ankur

Forum Jump:


Users browsing this thread: 1 Guest(s)