C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

For Loop Does not End

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
lakepeir@yahoo.com
Guest





PostPosted: Mon Nov 28, 2005 2:15 am    Post subject: For Loop Does not End Reply with quote



Hello,

I need help with my for loop. The loop does not end. It should end
when i is one less than uBound. What happens is that when i is 1 less
than uBound, the loop continues with a weird value 5432325 (I have no
idea how this value is generated, uBound is less than 10.) and then i
is equal to zero again. Here's the code:
for (int i=0; i < uBound; i++)
for (int j=0; j < uBound2; j++)
{
SafeArrayPutElement(psaArray, &lVal, &j);

}

Thanks!

Back to top
Sandeep
Guest





PostPosted: Mon Nov 28, 2005 2:50 am    Post subject: Re: For Loop Does not End Reply with quote



[email]lakepeir (AT) yahoo (DOT) com[/email] wrote:
Quote:
Hello,

I need help with my for loop. The loop does not end. It should end
when i is one less than uBound. What happens is that when i is 1 less
than uBound, the loop continues with a weird value 5432325 (I have no
idea how this value is generated, uBound is less than 10.) and then i
is equal to zero again. Here's the code:
for (int i=0; i < uBound; i++)
for (int j=0; j < uBound2; j++)
{
SafeArrayPutElement(psaArray, &lVal, &j);

}


You are sending the address of "j" in the function
"SafeArrayPutElements". Are you modifying the value of "j" there ?
It would be safer to declare "j" as a "const" parameter in function
"SafeArrayPutElements".


Back to top
Roy Smith
Guest





PostPosted: Mon Nov 28, 2005 2:53 am    Post subject: Re: For Loop Does not End Reply with quote



In article <1133144154.144645.37180 (AT) z14g2000cwz (DOT) googlegroups.com>,
[email]lakepeir (AT) yahoo (DOT) com[/email] wrote:

Quote:
Hello,

I need help with my for loop. The loop does not end. It should end
when i is one less than uBound. What happens is that when i is 1 less
than uBound, the loop continues with a weird value 5432325 (I have no
idea how this value is generated, uBound is less than 10.) and then i
is equal to zero again. Here's the code:
for (int i=0; i < uBound; i++)
for (int j=0; j < uBound2; j++)
{
SafeArrayPutElement(psaArray, &lVal, &j);

}

Thanks!

You are obviously leaving something out from the code you posted; how do
you know what the value of i is? I don't see any print statements. Could
you post a more complete code snippet?

Back to top
Ian
Guest





PostPosted: Mon Nov 28, 2005 3:09 am    Post subject: Re: For Loop Does not End Reply with quote

[email]lakepeir (AT) yahoo (DOT) com[/email] wrote:
Quote:
Hello,

I need help with my for loop. The loop does not end. It should end
when i is one less than uBound. What happens is that when i is 1 less
than uBound, the loop continues with a weird value 5432325 (I have no
idea how this value is generated, uBound is less than 10.) and then i
is equal to zero again. Here's the code:
for (int i=0; i < uBound; i++)
for (int j=0; j < uBound2; j++)
{
SafeArrayPutElement(psaArray, &lVal, &j);

}

SafeArrayPutElement must be doing something smelly on the stack, post

its code.

I'd look for an array that's one too small.

Ian

Back to top
lakepeir@yahoo.com
Guest





PostPosted: Mon Nov 28, 2005 3:20 am    Post subject: Re: For Loop Does not End Reply with quote

i++ increments the i value as it goes through the loop. The code
before it just initializes values such as the array, etc.

Code:

long lVal=0;
SafeArray psaArray;
SAFEARRAYBOUND rgsaBound[2];
rgsaBound[0].cElements = 4;
rgsaBound[0].lLbound = 0;
rgsaBound[1].cElements = 3;
rgsaBound[1].lLbound = 0;
psaArray = SafeArrayCreate(VT_VARIANT,2,rgsaBound);

Back to top
Gianni Mariani
Guest





PostPosted: Mon Nov 28, 2005 3:46 am    Post subject: Re: For Loop Does not End Reply with quote

[email]lakepeir (AT) yahoo (DOT) com[/email] wrote:
Quote:
Hello,

I need help with my for loop. The loop does not end. It should end
when i is one less than uBound. What happens is that when i is 1 less
than uBound, the loop continues with a weird value 5432325 (I have no
idea how this value is generated, uBound is less than 10.) and then i
is equal to zero again. Here's the code:
for (int i=0; i < uBound; i++)
for (int j=0; j < uBound2; j++)
{
SafeArrayPutElement(psaArray, &lVal, &j);

}

Your problem is not in this code.

Find out what changes i. Many debuggers have "watch points" which break
when the value of a location in memory changes.

Back to top
Victor Bazarov
Guest





PostPosted: Mon Nov 28, 2005 5:40 am    Post subject: Re: For Loop Does not End Reply with quote

[email]lakepeir (AT) yahoo (DOT) com[/email] wrote:
Quote:
i++ increments the i value as it goes through the loop. The code
before it just initializes values such as the array, etc.

Code:

long lVal=0;
SafeArray psaArray;
SAFEARRAYBOUND rgsaBound[2];
rgsaBound[0].cElements = 4;
rgsaBound[0].lLbound = 0;
rgsaBound[1].cElements = 3;
rgsaBound[1].lLbound = 0;
psaArray = SafeArrayCreate(VT_VARIANT,2,rgsaBound);

So?

SafeArray is not a standard C++ type. Neither is SAFEARRAYBOUND.
SafeArrayCreate is not a standard function. Perhaps you should
ask in a newsgroup where they are on topic...

V



Back to top
John Harrison
Guest





PostPosted: Mon Nov 28, 2005 8:35 am    Post subject: Re: For Loop Does not End Reply with quote

[email]lakepeir (AT) yahoo (DOT) com[/email] wrote:
Quote:
i++ increments the i value as it goes through the loop. The code
before it just initializes values such as the array, etc.

Code:

long lVal=0;
SafeArray psaArray;
SAFEARRAYBOUND rgsaBound[2];
rgsaBound[0].cElements = 4;
rgsaBound[0].lLbound = 0;
rgsaBound[1].cElements = 3;
rgsaBound[1].lLbound = 0;
psaArray = SafeArrayCreate(VT_VARIANT,2,rgsaBound);


You clearly have a bug in your program. You clearly haven't posted the
part of the code that has the bug yet. Keep trying.

john

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.