Micro Focus QTP (UFT) Forums
How to get out of infinite FOR loop... - 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: How to get out of infinite FOR loop... (/Thread-How-to-get-out-of-infinite-FOR-loop)



How to get out of infinite FOR loop... - sssidana - 07-19-2012

I am importing the data from the excel sheet for input and using for loop to put in the different values but at the end of the data in excel it starts again.How can I make it stop from going into the infinite FOR loop.Code is as following


Code:
datatable.Import("C:\Path")
rowcount=DataTable.GetRowCount


For r=1 to rowcount

DataTable.SetCurrentRow( r )


systemutil.Run"C:\Program Files (x86)\Internet Explorer\iexplore.exe"

Browser("Browser").WinEdit("Edit").Set "URL"

Browser("Browser").WinToolbar("Page Control").Click(button)

Browser("Browser").Page("AWB - Current Status").WebEdit("airWayBillTrackingNo").Set DataTable("AWBno", dtGlobalSheet)

Browser("Browser").Page("AWB - Current Status").WebButton("Track").Click(button)


'Browser("Browser").Sync

'-----a = Browser("Browser").Page("AWB - Current Status").Check (CheckPoint("AWB - Current Status_2"))

'---------msgbox("The Error for blank AWB : " & a)
'------Browser("Browser").Sync

'-------Browser("Browser").Page("AWB - Current Status_2").Link("Modify Search").Click

'---------b= Browser("AWB - Current Status").Page("AWB - Current Status").Check (CheckPoint("AWB - Current Status"))

'----------msgbox("The Error for AWB not found or only numbers : "& b)



'TODO:Check
strText=Browser("Browser").Page("AWB - Current Status").WebElement("AWB").GetROProperty("innertext")

strText1=Browser("Browser").Page("AWB - Current Status").WebElement("AWBO").GetROProperty("innertext")

strText2=Browser("Browser").Page("AWB - Current Status").WebElement("AWBD").GetROProperty("innertext")

strText3=Browser("Browser").Page("AWB - Current Status").WebElement("FlightD").GetROProperty("innertext")

strText4=Browser("Browser").Page("AWB - Current Status").WebElement("FlightDate").GetROProperty("innertext")

strText5=Browser("Browser").Page("AWB - Current Status").WebElement("Flightno").GetROProperty("innertext")

strText6=Browser("Browser").Page("AWB - Current Status").WebElement("FlightO").GetROProperty("innertext")

strText7=Browser("Browser").Page("AWB - Current Status").WebElement("FlightTime").GetROProperty("innertext")

strText8=Browser("Browser").Page("AWB - Current Status").WebElement("CurrentStatus").GetROProperty("innertext")
'Create Excel app
Set objAppExcel=CreateObject("Excel.Application")
objAppExcel.visible=True
'Open the worksbook
objAppExcel.workbooks.open "C:\Users\User\Desktop\TRACK.xls"
'Set focus on the workbook
objAppExcel.Workbooks("TRACK.xls").Activate
'Create work sheet obj
Set objExcelSheet=objAppExcel.ActiveWorkbook.Worksheets(1)
'Write to work sheet

'Save worksheet
'objExcelSheet.saveAs "C:\Users\User\Desktop\TRACK.xls"
'Clear  obj reference
'----Set objExcelSheet=Nothing
'quit app
'----objAppExcel.quit
'-----Set objAppExcel=Nothing


'Write to work sheet
objExcelSheet.cells(1,1)=strText

objExcelSheet.cells(1,2)=strText1



objExcelSheet.cells(1,3)=strText2



objExcelSheet.cells(1,4)=strText3



objExcelSheet.cells(1,5)=strText4



objExcelSheet.cells(1,6)=strText5



objExcelSheet.cells(1,7)=strText6



objExcelSheet.cells(1,8)=strText7



objExcelSheet.cells(1,9)=strText8
'Save worksheet
objExcelSheet.saveAs "C:\Users\User\Desktop\TRACK.xls"
'Clear  obj reference
Set objExcelSheet=Nothing
'quit app
objAppExcel.quit
Set objAppExcel=Nothing

Browser("Browser").Close


Next



RE: How to get out of infinite FOR loop... - vIns - 07-19-2012

Plz Use 'Exit For'


RE: How to get out of infinite FOR loop... - sssidana - 07-19-2012

Hey it is still not working I am using the following code


Code:
datatable.Import("C:\Path")
rowcount=DataTable.GetRowCount


For r=1 to rowcount

DataTable.SetCurrentRow(r)


systemutil.Run"C:\Program Files (x86)\Internet Explorer\iexplore.exe"

Browser("Browser").WinEdit("Edit").Set "http://URL"

Browser("Browser").WinToolbar("Page Control").Click(button)

Browser("Browser").Page("AWB - Current Status").WebEdit("airWayBillTrackingNo").Set DataTable("AWBno", dtGlobalSheet)

Browser("Browser").Page("AWB - Current Status").WebButton("Track").Click(button)


'Browser("Browser").Sync

'-----a = Browser("Browser").Page("AWB - Current Status").Check (CheckPoint("AWB - Current Status_2"))

'---------msgbox("The Error for blank AWB : " & a)
'------Browser("Browser").Sync

'-------Browser("Browser").Page("AWB - Current Status_2").Link("Modify Search").Click

'---------b= Browser("AWB - Current Status").Page("AWB - Current Status").Check (CheckPoint("AWB - Current Status"))

'----------msgbox("The Error for AWB not found or only numbers : "& b)



'TODO:Check
strText=Browser("Browser").Page("AWB - Current Status").WebElement("AWB").GetROProperty("innertext")

strText1=Browser("Browser").Page("AWB - Current Status").WebElement("AWBO").GetROProperty("innertext")

strText2=Browser("Browser").Page("AWB - Current Status").WebElement("AWBD").GetROProperty("innertext")

strText3=Browser("Browser").Page("AWB - Current Status").WebElement("FlightD").GetROProperty("innertext")

strText4=Browser("Browser").Page("AWB - Current Status").WebElement("FlightDate").GetROProperty("innertext")

strText5=Browser("Browser").Page("AWB - Current Status").WebElement("Flightno").GetROProperty("innertext")

strText6=Browser("Browser").Page("AWB - Current Status").WebElement("FlightO").GetROProperty("innertext")

strText7=Browser("Browser").Page("AWB - Current Status").WebElement("FlightTime").GetROProperty("innertext")

strText8=Browser("Browser").Page("AWB - Current Status").WebElement("CurrentStatus").GetROProperty("innertext")
'Create Excel app
Set objAppExcel=CreateObject("Excel.Application")
objAppExcel.visible=True
'Open the worksbook
objAppExcel.workbooks.open "C:\Users\User\Desktop\TRACK.xls"
'Set focus on the workbook
objAppExcel.Workbooks("TRACK.xls").Activate
'Create work sheet obj
Set objExcelSheet=objAppExcel.ActiveWorkbook.Worksheets(1)
'Write to work sheet

'Save worksheet
'objExcelSheet.saveAs "C:\Users\User\Desktop\TRACK.xls"
'Clear  obj reference
'----Set objExcelSheet=Nothing
'quit app
'----objAppExcel.quit
'-----Set objAppExcel=Nothing


'Write to work sheet
objExcelSheet.cells(r,1)=strText

objExcelSheet.cells(r,2)=strText1



objExcelSheet.cells(r,3)=strText2



objExcelSheet.cells(r,4)=strText3



objExcelSheet.cells(r,5)=strText4



objExcelSheet.cells(r,6)=strText5



objExcelSheet.cells(r,7)=strText6



objExcelSheet.cells(r,8)=strText7



objExcelSheet.cells(r,9)=strText8
'Save worksheet
objExcelSheet.saveAs "C:\Users\User\Desktop\TRACK.xls"
'Clear  obj reference
Set objExcelSheet=Nothing
'quit app
objAppExcel.quit
Set objAppExcel=Nothing

Browser("Browser").Close
If r=("2") Then

    Exit for

End If

Next
***there are only 2 data values in excel file****


RE: How to get out of infinite FOR loop... - sree.85 - 07-20-2012

go to File->Setting->run->Select one iteration only

try this it may solve your problem