Re: Substring Out of Range in qtp script (422 Views)
Reply
Respected Contributor
rpagadala09
Posts: 379
Registered: ‎11-19-2010
Message 1 of 6 (480 Views)
Accepted Solution

Substring Out of Range in qtp script

Hi,

 

 I am new to QTP.

 

I have developed the below script ,and  when I tried to run the below script, getting  error as  "substring out of range" for  Number.xlsx(see the atttached)

Bascillay I am  trying to do paramerization using excel for  addition of 2 numbers.

 

Could  some one please guide me on the below 2  questions.

1.Is my script is correct?

2.Why I am getting  substring out of range"

 

 

***************************Script********************************************

Dim worksheet,Num1,Num2

Set myxl = createobject("excel.application")
 
myxl.Workbooks.Open "C:\Number.xlsx"
myxl.Application.Visible = true

set mysheet = myxl.ActiveWorkbook.Worksheets("Number.xlsx")

Row=mysheet.UsedRange.Rows.Count
 
For i= 2 to Row
 
Num1=mysheet.cells(i,1).value
Num2=mysheet.cells(i,2).value
 
wait 1

 R= Num1 * Num2

Msgbox("Result is  :  "  & R)
 
Next
 
'Close the Workbook
myxl.ActiveWorkbook.Close
 
'Close Excel
myxl.Application.Quit
 
'Release the objects
Set mysheet =nothing
Set myxl = nothing

 

 

***************************Script********************************************

 

Please use plain text.
HP Expert
vzamoraz
Posts: 502
Registered: ‎04-12-2012
Message 2 of 6 (475 Views)

Re: Substring Out of Range in qtp script

[ Edited ]

Hi,

 

     I am not able to see the attached.

     what line is showing the error?

     

 

Best Regards

 

If you have a valid contract with HP feel free to visit our FT/QTP Support Customer Forums: <<http://h30499.www3.hp.com/t5/Functional-Testing-QTP/ct-p/sws-Fun_Test >>
You can create an accout with your HP credentials.

Please use plain text.
Respected Contributor
rpagadala09
Posts: 379
Registered: ‎11-19-2010
Message 3 of 6 (471 Views)

Re: Substring Out of Range in qtp script

Hi,

 

Error is  getting  @ this line set mysheet = myxl.ActiveWorkbook.Worksheets("Number.xlsx")

 

I have attached the xls sheet.

 

Thanks,

Raj

 

Please use plain text.
Occasional Advisor
Shruti_Sagar
Posts: 17
Registered: ‎02-13-2013
Message 4 of 6 (453 Views)

Re: Substring Out of Range in qtp script

Error is at line
set mysheet = myxl.ActiveWorkbook.Worksheets("Number.xlsx")
"Number.xlsx" is not a worksheet , instead it is the file name
Sheetname can be refereed by sequence no 1 ,2 3 etc or with Sheetname.
By default each excel comes with 3 sheets so if you are trying to refer data in sheet1 the line will be

set mysheet = myxl.ActiveWorkbook.Worksheets("Sheet1")
Regards:
Shruti Sagar Mishra
Software QA Analyst
################
Please Mark kudos on left , if this answers your question
################
Please use plain text.
Respected Contributor
rpagadala09
Posts: 379
Registered: ‎11-19-2010
Message 5 of 6 (436 Views)

Re: Substring Out of Range in qtp script

Hi Shruthi,

 

Thank You so  much!   I will let you know the  Results!

 

 

Thanks,

Raj

Please use plain text.
Occasional Advisor
Shruti_Sagar
Posts: 17
Registered: ‎02-13-2013
Message 6 of 6 (422 Views)

Re: Substring Out of Range in qtp script

For more information on the same please have a look on below

http://softwaretestingperfection.blogspot.com/2013/09/excel-handling-in-qtp.html
Regards:
Shruti Sagar Mishra
Software QA Analyst
################
Please Mark kudos on left , if this answers your question
################
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation