-
While loops not behaving
Heres the PCode for a function
Code:
while(!file.EOF)
{
:1
while(!file.EOF)
{
:2
file.MoveNext();
}
:3
}
file.close();
Here is what im doing. I'm pulling things from a recordset... everything works fine, except, when the second loop hits a EOF.
This prints everything out that I want it to, it returns everything to the browser i want to, but, when the second loop hits an EOF it exits and stops loading my page.
Initialy I thought when the second loop hit EOF it was also exiting the first loop. But that is not the case. To me, it looks as if some kind of an error is happening when it hits EOF and stops loading my page. Yes, that must be it, because the bottom section of the interface is also cut off.. meaning no other ASP or HTML is executed. I know this is some kind of EOF problem because it ALWAYS happens with the last recordset (or last product in the table). When the last product is hit, it prints everything inside of that loop, then exits, and stops loading everything else. So the error is happening when the loop terminates?
As to what this error is I have no idea. This ever happen to anyone?
-
Code:
//objProducts is defined up here
while(!objProducts.EOF)
{
intQuantity = objProducts('intQuantity').value;
pCycleGuid = objProducts('guidProductID');
while (pCycleGuid == objProducts('guidProductID') && !objProducts.EOF)
{
//do stuff here
pCycleGuid = objProducts('guidProductID').value;
objProducts.MoveNext();
}
//on EOF, the second loop breaks here
//and does not execute this portion
}
objProducts.close();
//allthough im not sure if its actually closing since it never reaches
//this part down here.
-
Wow... I just fixed the problem. This is the wierdest solution yet...
Code:
while ((!objProducts.EOF) && (pCycleGuid == objProducts('guidProductID').value) )
I just switched the while loop around. Anyone konw why that worked?
-
No idea...
As to the leaving.. once you moved to the last record the eof flag is set.
If you need to loop for display purpose, I personally open as static and then loop with a counter (you can get the number of records returned via rst.recordcount) so you don't miss any records.
Vince