 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
lakepeir@yahoo.com Guest
|
Posted: Mon Nov 28, 2005 2:15 am Post subject: For Loop Does not End |
|
|
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
|
Posted: Mon Nov 28, 2005 2:50 am Post subject: Re: For Loop Does not End |
|
|
[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
|
Posted: Mon Nov 28, 2005 2:53 am Post subject: Re: For Loop Does not End |
|
|
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
|
Posted: Mon Nov 28, 2005 3:09 am Post subject: Re: For Loop Does not End |
|
|
[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
|
Posted: Mon Nov 28, 2005 3:20 am Post subject: Re: For Loop Does not End |
|
|
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
|
Posted: Mon Nov 28, 2005 3:46 am Post subject: Re: For Loop Does not End |
|
|
[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
|
Posted: Mon Nov 28, 2005 5:40 am Post subject: Re: For Loop Does not End |
|
|
[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
|
Posted: Mon Nov 28, 2005 8:35 am Post subject: Re: For Loop Does not End |
|
|
[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 |
|
 |
|
|
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
|
|