Hello

I have a form where I have a lot of code perheps about 1000 pages.

Now in an event I have 160 lines of this code that I show below. I am showing 2 lines to give an example here:

for(int i = 0; i < 6; i++ ){for( int j = 0; j < 50; j++ ){if( All[i][j][120] != "" ){button127->Width = 42; button127->Height = 23; button127->Text = All[i][j][120]->ToString();button127->BackColor = Color::Green;button127->FlatAppearance->MouseDownBackColor = System::Drawing::Color::Green; button127->FlatAppearance->MouseOverBackColor = System::Drawing::Color::Green;}}}
for(int i = 0; i < 6; i++ ){for( int j = 0; j < 50; j++ ){if( All[i][j][121] != "" ){button128->Width = 42; button128->Height = 23; button128->Text = All[i][j][121]->ToString();button128->BackColor = Color::Green;button128->FlatAppearance->MouseDownBackColor = System::Drawing::Color::Green; button128->FlatAppearance->MouseOverBackColor = System::Drawing::Color::Green;}}}

Now on the 122:th line, I will receive a compileerror that I haven´t seen before that says:
fatal error C1061: compiler limit : blocks nested too deeply

Is it to much for the compiler. There is nothing wrong with the code as I have tested this. If I take line 122-160 away it do compiles.

Can I adjust any setting to make this work. ?

Thank you

There code itself seems okay, besides that it is poorly formatted.
You need to use arrays here. If I'm guessing right, this will shrink down the code to less than 10 pages and won't give the compiler trouble anymore.

I do use 3 dimensions List here. So that should work like an array ?

The problem is that I beleive I need to have 160 lines of code that repeats the thing as I have 160 buttoncontrols on the form, so I cant put the buttons in a List<>.
So I think I have to hardcode the different buttons out on each line like this ?

Or is there a way in my example to put the buttons in an array ?

I meant to use an array for the buttons. Since they seem to be pointers, you can easily create an array holding all of your buttons and thus get rid of all the duplicate code.

Okay that is wonderful, I didn´t know that was possible really.

How would that be possible for this example if we put a width of 100 to button1 and button2 ?

int setWidth = 100;

for( int i = 0; i < 2; i++ )
{
    //Set width of 100 for button1 and button2 from an array
}

Create the array like this (replace Button with the actual button class name):

Button* buttons[]={button1,button2,button3, ...};

Then you can write:

int setWidth = 100;
for( int i = 0; i < 2; i++ )
{
    buttons[i]->SetWidth(100);
}

Thank you, I do have a problem still. I think I need to use ^ instead of the * but one compile error remains when I try this code:

I get this error wich I am not sure what it means here:
System::Windows::Forms::Button ^' : a native array cannot contain this managed type

Button^ buttons[]={button1,button2,button3};

Try a vector or something equivalent.
What you're using is not C++, by the way.

Okay, I am trying to do this with a vector too but also get a compile error. I beleive it is close but I am missing something out? Thank you

'button' : undeclared identifier
left of '->Add' must point to class/struct/union/generic type

List<System::Windows::Forms::Button^>^ button = gcnew List<System::Windows::Forms::Button^>();
button->Add(button1);
button->Add(button2);

Strangely this compiled so I will try to use this and so how it goes.
Thank you alot for your help

List<Button^>^ button = gcnew List<Button^>();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.