[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 22

 

People, help me out!

                      if(OPrazH<razH && OPrazH>0)              
                        {
                         f1=1;                                 
                         xDelH[countDH][0]=High[j];            
                         xDelH[countDH][1]=Time[j];
                         Print(xDelH[countDH][0]);
                         countDH++;
                         break;
                        }

I'm writing this code (this is a snippet), all variables and arrays are set, the counter counts. Initially countDH=0. But there is a problem: nothing is written to xDelH array. Print (High[j], Time[j], countDH) returns the correct result but xDelH[countDH][0] always gives 0. Checking via the array size also returns 0.

Even if you write xDelH[countDH][0]=0.01; it still gives 0. Whatever I do, no matter where I put this code, it does not work anywhere.

What may it be because of? What is the reason? Please help me!

 
WindSW:

People, help me out!

I'm writing this code (this is a fragment), all variables and arrays are set, counter counts. But there is a problem with xDelH array, nothing is written to it. Print (High[j], Time[j], countDH) gives me correct result but xDelH[countDH][0] always returns 0. Checking via array size also returns 0. What may be the reason? What is the reason? Please help me!

Even if I write xDelH[countDH][0]=0.01; it still produces 0.

Check if xDelH is of the double type. Is this if inside for. The break operator is somehow wrongly placed. If you do it like below, what will happen?

double xDelH [1][1];
int countDH=0;

xDelH[countDH][0]=0.01; // точка а не запятая
Print(DoubleToStr(xDelH[countDH][0],2));
 
WindSW:

People, help me out!

I'm writing this code (this is an excerpt), all variables and arrays are set, the counter counts. Initially countDH=0. But there is a problem: nothing is written to xDelH array. Print (High[j], Time[j], countDH) returns correct results, while xDelH[countDH][0] always gives 0. Checking via the array size also returns 0.

Even if you write xDelH[countDH][0]=0.01; it still gives 0. Whatever I do, no matter where I put this code, it does not work anywhere.

What may it be because of? What is the reason? Please help me!

Another reason may be not declared size of array xDelH[][].
 
I have double xDelH[][2]; if is in two for, one of which goes through j. The code you wrote works - it gives 0.01
 
WindSW:
I have double xDelH[][2]; if is in two for, one of which goes through j. The code you wrote works - it outputs 0.01

In your version, the size of the array is not specified in dimension 0, but in the example above it is:

double xDelH [1][1];
 

Thank you! It's all working. Selected the size as follows: ArrayResize(xDelH,100);

One more question: if the array fills all 100 cells, and countDH will count to 120 for example, will the array size automatically increase to 120, or will I have to regularly resize the array another way?

 
WindSW:

Thank you! It's all working. Selected the size as follows: ArrayResize(xDelH,100);

One more question: if the array fills all 100 cells, and countDH will count to 120 for example, will the size of the array automatically increase to 120, or will I have to resize the array regularly in another way?

Nothing will be done automatically. If necessary:

ArrayResize (xDelH, countDH + 1);
 
TarasBY:

Nothing will be done automatically. If necessary:


Thank you!
 

Alternatively, you can set more cells at once, e.g. 1000 if you know there will be no more than 1000. If you fill the array inside for, then in the same for you define the maximum number of iterations and before for you can change the size of the array, e.g..:

double xDelH[][2];

int N=120;
ArrayResize(xDelH, N);

for (int i=0; i<=N; i++)
{
// ...
}
 
paladin80:

Alternatively, you can set more cells at once, e.g. 1000 if you know there will be no more than 1000. If you fill the array inside for, then in the same for you define maximal number of iterations and before for you can resize the array, for example..:


In my code, it's more convenient to define number of iterations through ArrayRange.

Why, if I write xDelH[countDH][0]=HBar[countH][0]; it will give 0 (although HBar[countH][0] is already filled and has its own value). Can I do this at all?