Micro Focus QTP (UFT) Forums
Concatenating counter and object value - 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: Concatenating counter and object value (/Thread-Concatenating-counter-and-object-value)



Concatenating counter and object value - Anum Saleem - 02-21-2012

In do while loop i want to concatenate txtFirstName with counter value like Kim1
Kim2
code im using for it:
Code:
counter = 1
Do
Browser("Softronic - HCMS").Page("Softronic - HCMS_2").WebList("ddlTitle").Select "Ms."
Fname = Browser("Softronic - HCMS").Page("Softronic - HCMS_2").WebEdit("txtFirstName").Set("Kim")
counterstr = CStr(counter)
Fname = Fname + counterstr
Loop while counter <= 5
counter = counter + 1
Fname shows only counter value i.e 1 , it is not showing Kim1 displays 1
Tell me what is wrong with the code?how can i concatenate


RE: Concatenating counter and object value - inborntester - 02-21-2012

Aru you sure Fname = Browser("Softronic - HCMS").Page("Softronic - HCMS_2").WebEdit("txtFirstName").Set("Kim") will return Kim. If Kim is the value which is always set in webedit box then when do use it dircetly like Fname = "Kim" + counterstr. if your need is get back the set value is better to use GetROProperty method.




RE: Concatenating counter and object value - Ankesh - 02-21-2012

Hi,

The question that you are asking is not clear.

Let me rephrase your question. Do you want to set the values (such as Kim1,Kim2) in the txtFirstNameField? If yes then use the below code


Code:
counter = 1
Do
  Browser("Softronic - HCMS").Page("Softronic - HCMS_2").WebList("ddlTitle").Select "Ms."
  strVar=Cstr("Kim"&counter)
  Browser("Softronic - HCMS").Page("Softronic - HCMS_2").WebEdit("txtFirstName").Set strVar
  counter = counter + 1
Loop while counter <= 5
feel free to post in case this doesnt suits your requirement.

Regards,
Ankesh


RE: Concatenating counter and object value - Anum Saleem - 02-21-2012

Yes exactly! thank u so much..This code fulfill my requirements.