How to generate Random value of any type based on the input
How to generate Random value of any type based on the input
MsgBox RandomValue("char",10)
MsgBox RandomValue("num",10)
MsgBox RandomValue("alphanumeric",10)
MsgBox RandomValue("",10)
Function RandomValue(rType, Cnt)
Randomize()
dim CharacterSetArray
Select Case LCase(rType)
Case "char"
CharacterSetArray = Array(Array(Cnt, "abcdefghijklmnopqrstuvwxyz"), Array(0, ""))
Case "num"
CharacterSetArray = Array(Array(Cnt, "0123456789"), Array(0, ""))
Case "alphanumeric"
CharacterSetArray = Array(Array(Cnt/2, "abcdefghijklmnopqrstuvwxyz"), Array(Cnt/2, "0123456789"))
Case Else
CharacterSetArray = Array(Array(Cnt/2, "abcdefghijklmnopqrstuvwxyz"), Array(Cnt/2, "0123456789"))
End select
dim i,j,Count,Chars,Index,Temp
for i = 0 to UBound(CharacterSetArray)
Count = CharacterSetArray(i)(0)
Chars = CharacterSetArray(i)(1)
for j = 1 to Count
Index = Int(Rnd() * Len(Chars)) + 1
Temp = Temp & Mid(Chars, Index, 1)
next
next
dim TempCopy
do until Len(Temp) = 0
Index = Int(Rnd() * Len(Temp)) + 1
TempCopy = TempCopy & Mid(Temp, Index, 1)
Temp = Mid(Temp, 1, Index - 1) & Mid(Temp, Index + 1)
loop
RandomValue = TempCopy
End Function
MsgBox RandomValue("num",10)
MsgBox RandomValue("alphanumeric",10)
MsgBox RandomValue("",10)
Function RandomValue(rType, Cnt)
Randomize()
dim CharacterSetArray
Select Case LCase(rType)
Case "char"
CharacterSetArray = Array(Array(Cnt, "abcdefghijklmnopqrstuvwxyz"), Array(0, ""))
Case "num"
CharacterSetArray = Array(Array(Cnt, "0123456789"), Array(0, ""))
Case "alphanumeric"
CharacterSetArray = Array(Array(Cnt/2, "abcdefghijklmnopqrstuvwxyz"), Array(Cnt/2, "0123456789"))
Case Else
CharacterSetArray = Array(Array(Cnt/2, "abcdefghijklmnopqrstuvwxyz"), Array(Cnt/2, "0123456789"))
End select
dim i,j,Count,Chars,Index,Temp
for i = 0 to UBound(CharacterSetArray)
Count = CharacterSetArray(i)(0)
Chars = CharacterSetArray(i)(1)
for j = 1 to Count
Index = Int(Rnd() * Len(Chars)) + 1
Temp = Temp & Mid(Chars, Index, 1)
next
next
dim TempCopy
do until Len(Temp) = 0
Index = Int(Rnd() * Len(Temp)) + 1
TempCopy = TempCopy & Mid(Temp, Index, 1)
Temp = Mid(Temp, 1, Index - 1) & Mid(Temp, Index + 1)
loop
RandomValue = TempCopy
End Function
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Thu Jun 19, 2014 11:31 am by thomasdfg
» How to identify the object when it is dynamically changing behavior
Wed Jun 18, 2014 6:37 pm by thomasdfg
» Patches for QTP 10, 11, 11.5
Wed Jun 18, 2014 6:04 pm by thomasdfg
» Retrieving data from Txt file into datatable
Wed Jun 18, 2014 5:32 pm by thomasdfg
» VB Script to count number of links in a web page.
Wed Jun 18, 2014 4:51 pm by thomasdfg
» Customized HTML reports in QTP
Wed Jun 18, 2014 4:42 pm by thomasdfg
» how to print values into a field of a web page, from a data table in qtp?
Wed Jun 18, 2014 4:37 pm by thomasdfg
» How to delete cookies using QTP?
Wed Jun 18, 2014 4:30 pm by thomasdfg
» When UFT Does Not Identify an Object
Wed Jun 18, 2014 4:23 pm by thomasdfg