Micro Focus QTP (UFT) Forums
Creating 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Creating Random String (/Thread-Creating-Random-String)



Creating Random String - SomeIntern - 08-21-2013

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.
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