[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 184

 
   double Mas[];//массив куда надо заносить данные

If it outputs zeros, it's better to attach code rather than explaining it on your fingers.

If an open array is declared, it is advisable to do ArrayResize, or declare a larger dimension right away.

 
double mas[];
int start()
  {
  double v1=mas[1];
  mas[1]=89;
  double v2=mas[1];
  ArrayResize(mas,iBars(NULL,0));
  double v3=mas[1];
  mas[1]=89;
  double v4=mas[1];
  Alert(v1,"-",v2,"-",v3,"-",v4);
  return(0);
  }

The script is purely for fun, but you can also catch Alert(GetLastError()); getting

ERR_ARRAY_INDEX_OUT_OF_RANGE4002The array index is out of range
 
splxgf:

If it outputs zeros, it's better to attach code rather than explaining it on your fingers.

If an open array is declared, it's advisable to do ArrayResize, or declare a larger dimension right away.

I have already attached the code in the first post. There just need to add a couple of correct lines somewhere to form the array. That was exactly the main question).

In fact, I think it should be something like this somewhere:

ArrayResize(Mas,n);

Mas[n]={diff};

n is the new dimensionality, diff values of the resulting differences.

But it doesn't work that way, it prints the difference 0.00000. I have already tried to insert the difference in the loop, behind the loop and even in the condition.

In short, I am in a stupor).

If you know how to write it, I will be very grateful to you.

 
splxgf:

The script is purely for fun, but you can also catch Alert(GetLastError()); getting

ERR_ARRAY_INDEX_OUT_OF_RANGE4002The array index is out of range

Well, it turns out that you explicitly specify both the array's size and value in the code. It is this very thing that I have understood in the article.

But it somehow does not work with my example.(.

 
NickXXX:

explicitly specify both the dimension and the value of the array in the code

There are no other options.

  double v1=mas[1];
  mas[1]=89;
  Alert(GetLastError());
  double v2=mas[1];
  Alert(GetLastError());
  ArrayResize(mas,iBars(NULL,0));

Elements are not created when you access them.

 
splxgf:

There are no other options.

Elements are not created when they are accessed.

Okay, look. Do I get it right?

In your example, you're creating a one-dimensional array consisting of a single value of 89.

By the way, by dimensionality I meant the number of elements in a one-dimensional array. I thought that you can change it over the course of the program. After all, it's not for nothing that we initially specify our array not explicitly. I.e. for example:

double Mas[]; //initialize one-dimensional array

int n=0; //will be useful for the number of array elements

Further, like in my example, we do the following loop

for(...)

{

if(...)//the condition we are interested in

{

n++;// count how many times it worked

diff=... values we are interested in

}

}

and then somewhere else we stuff our one-dimensional array Mas[n] with diff values, n being the number of elements

I thought it's quite normal and can be done that way... Or is it?

 

Before for, add an ArrayResize to the required number of elements

For example, the point

  ArrayResize(mas,iBars(NULL,0));

is oriented on the number of bars in the chart in the current window, or you can just specify any close to astronomical number instead of iBars.

The array is initially created empty, before accessing it, you need to specify how many elements you want to store in it. Post the full code, it will be easier to navigate.

 
splxgf:

Before for, add an ArrayResize to the required number of elements

For example, the point

is oriented on the number of bars of the chart in the current window, or you can just specify any close to astronomical number instead of iBars.

But before for we don't know the number of elements, we will know it only when we calculate the number of if condition. I tried to put ArrayResize after for, it outputs 0 as elements.
 

In the example I show that you can't use an array that doesn't have a number of elements marked.

The first two calls cause an error and return 0.

To get rid of the cockroaches, just write

double mas[999999];

If it works, deal with the cockroaches.

 
splxgf:

In the example I show that you can't use an array that doesn't have a number of elements marked.

The first two calls cause an error and return 0.

To get rid of the cockroaches you've got.

If it works, deal with the cockroaches.

You don't have to specify number of elements from the beginning, double Mas[] construction is also suitable.