Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Random String
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create a random number starting with an alphabet QTPmate 4 5,058 07-31-2014, 09:29 AM
Last Post: QTPmate
  Random Values from Drop-Down profqa 5 6,917 12-06-2013, 09:01 AM
Last Post: basanth27
  Replace a string in a word document with another string rekha.naik 8 16,890 11-14-2013, 12:58 PM
Last Post: pranikgarg
  Problem in creating excel object kriday 1 2,853 07-13-2013, 12:45 PM
Last Post: Ankur
  Creating multiple lines under a header - SAP Fredodo 7 6,975 01-02-2013, 04:54 PM
Last Post: Saleel Prabhu

Forum Jump:


Users browsing this thread: 1 Guest(s)