# Thread: Appending a number on the end of a 'unique' value

1. ## Appending a number on the end of a \'unique\' value

Hello,

Is their a way to append a number on the end of a 'unique' value that gets entered into an application. For example, if the required/unique field is OPERATOR-1 as recorded and I want to increment 1 sequentially on the next playback how can I do that? So next playback value entered would be OPERATOR-2,etc.

I am using the CONCATENATE function on other test cases but have come across a couple test cases where the unique value must be on the right. I am looking at some EXCEL functions now and do not see anything that will accomplish this.

2. ## Re: Appending a number on the end of a \'unique\' value

try this

UniqueField = "OPERATOR-1"
sUnique = split(UniqueField, "-")
iNum = Cint(sUnique(1)) + 1
msgbox sUnique(0) &amp; "-" &amp; iNum

3. ## Re: Appending a number on the end of a \'unique\' value

I use DDMMYYYHHMMSS to generate a valid random number that need not be tracked from run to run like the method you describe:

'================================================= ============================
Public Function GetDateTime(dateTime)
' Create a unique user name
' using current date &amp; time
'
' Output: dateTime in format yymmddhhmmss
Dim yr, mth, dy, hh, mm, ss
dy = DatePart("D", Now)
If Len(dy) &lt; 2 Then
dy = "0" &amp; dy
End If
mth = DatePart("M", Now)
If Len(mth) &lt; 2 Then
mth = "0" &amp; mth
End If
yr = DatePart("YYYY", Now)
hh = DatePart("H", Now)
If Len(hh) &lt; 2 Then
hh = "0" &amp; hh
End If
mm = DatePart("N", Now)
If Len(mm) &lt; 2 Then
mm = "0" &amp; mm
End If
ss = DatePart("S", Now)
If Len(ss) &lt; 2 Then
ss = "0" &amp; ss
End If
dateTime = yr &amp; mth &amp; dy &amp; hh &amp; mm &amp; ss
End Function
'================================================= =======

Mark Smith.

4. ## Re: Appending a number on the end of a \'unique\' value

Try the Below Function which will generate the timestamp with seconds which is always Unique

Function UniqueValue
arrDateTime=Split(Now," ")
arrTime=Split(arrDateTime(1),":")
UniqueValue=arrTime(0)&amp;arrTime(1)&amp;arrTime( 2)
End Function

MsgBox UniqueValue

5. ## Re: Appending a number on the end of a \'unique\' value

Thank you for the replies. I will try these methods and need to make sure the data field will support OPERATOR- + DATETIMESTAMP length. This should work. I'll post back and let you know.

6. ## Re: Appending a number on the end of a \'unique\' value

If I use the output var UniqueValue how do I append that onto a value that I am setting? For example the first time through is ITEMR1. So I need ITEM + UniqueValue.

7. ## Re: Appending a number on the end of a \'unique\' value

Parameter("X") = "ITEM" &amp; GetUniqueValue

8. ## Re: Appending a number on the end of a \'unique\' value

Tarun, thank you. BTW, I bought your QTP unplugged. It's great reference.

I've got:

Function UniqueValue
arrDateTime=Split(Now," ")
arrTime=Split(arrDateTime(1),":")
UniqueValue=arrTime(0)&amp;arrTime(1)&amp;arrTime( 2)
End Function

I set a parameter name = p_Item
Selected parameter type = environment
I set value to : Parameter("p_Item") = "ITEM" &amp; UniqueValue

Does this look right?

9. ## Re: Appending a number on the end of a \'unique\' value

Yep, looks good

10. ## Re: Appending a number on the end of a \'unique\' value

Is it possible to store that unknown UniqueValue if I need to use this later on in the test. For example, code worked and generated ITEM13402. If I need to use ITEM13402 without knowing what it will be before I start the test how can accomplish that?

I was thinking of calling UniqueValue something more descriptive for each test case that I need a unique value but was wondering if QTP will hold all of those variables when it moves to the next test case.

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.