08-21-2013, 09:10 PM
(This post was last modified: 08-21-2013, 09:49 PM by SomeIntern.)
hello everyone,
So I am new to QTP and wanted to see if i could get a little help. So I want to create a random string that will populate a Last Name field. I have this code that I found on another webpage that basically does what I want. The only problem is that it populates the field with special characters as well and I only want alpha characters.
My knowledge of VB Script is nonexistent, so any help would be greatly appreciated.
Regards,
Erik
I have actually found a solution
I changed the code posted on a website to include lowercase letters instead of numbers. I'll post it in case anyone else ever needs it.
So I am new to QTP and wanted to see if i could get a little help. So I want to create a random string that will populate a Last Name field. I have this code that I found on another webpage that basically does what I want. The only problem is that it populates the field with special characters as well and I only want alpha characters.
Code:
Function RandomValue(vLength)
For x=1 To vLength
Randomize
vChar = Int(89*Rnd) + 33
If vChar = 34 Then
vChar = 39
End if
RandomValue = RandomValue & Chr(vChar)
Next
End Function
My knowledge of VB Script is nonexistent, so any help would be greatly appreciated.
Regards,
Erik
I have actually found a solution
I changed the code posted on a website to include lowercase letters instead of numbers. I'll post it in case anyone else ever needs it.
Code:
Function GetRandom(Count)
Randomize
For i = 1 To Count
If (Int((1 - 0 + 1) * Rnd + 0)) Then
GetRandom = GetRandom & Chr(Int((90 - 65 + 1) * Rnd + 65))
Else
GetRandom = GetRandom & Chr(Int((97 - 122 + 1) * Rnd + 122))
End If
Next
End Function