I'm doing a "magic square" program and I'm having trouble with a button. It is supposed to stay active for as many clicks as it takes to fill the array storing the numbers, then become disabled. The button stops working the first time i click it though, and i dont know what i'm doing wrong. could someone help me please?

heres the code for my button.

void CLab10Dlg::OnEnterDataButton() 
{
	// TODO: Add your control notification handler code here
	GetDlgItemText(IDC_ROW_NUM, m_row_num);
	GetDlgItemText(IDC_COL_NUM, m_col_num);
	GetDlgItemText(IDC_DATA, m_data);
	int row_num = atoi((LPCTSTR)m_row_num);
	int col_num = atoi((LPCTSTR)m_col_num);
	int data = atoi((LPCTSTR)m_data);
	int i;
	if(i < num_rows_cols)
	{
		magic_array[row_num-1][col_num-1] = data;
		i++;
	}
	if(i >= num_rows_cols)
		m_enter_data_button.EnableWindow(false);
		
}

and when I initialize "i" to zero, i get the error message:
error C2252: 'i' : pure specifier can only be specified for functions

I may be wrong on this, but I'll take a crack it. It looks as if you're declaring an int i, assigning it no value which in turn will leave some unknown garbage data. And since your array is probably not too large num_row_cols will probably be lower than the garbage data which can be as high as 65,536.

[B]int[/B] i;
[B]if[/B](i < num_rows_cols)
{
magic_array[row_num-1][col_num-1] = data;
   i++;
}
[B]if[/B](i >= num_rows_cols)
   m_enter_data_button.EnableWindow([B]false[/B]);

Edit: My apologies I didn't see the statement under your code.

i know i need to initialize it, but i must be doing it wrong, because whenever i intitialize it to zero i get an error message.

I looked up this error and here is what I found.

Error:
pure specifier can only be specified for functions

Suggestion
In a class definition, you are not allowed to set variables or call functions (including other class constructors). Thus code such as int a = 0; and vector<int> b(10); is not allowed. Setting variables and calling functions should be done in constructors. To make a function a pure virtual function, one that must be overridden by a derived class, set the function =0, as in void Draw() = 0;

okay i'll try that thx.

I still can't get it right. Could someone give me an example of something like what im trying to do? Or atleast tell me exactly what i have wrong. This is the only way i can think of to get the button to disable, and obviously its wrong.
My professor told me to define all of my variables in the header file directly before the "protected" area. And when i put the variable "i" there, that's when i get the error that i posted above.

Thx in advance for any help that you may offer me.

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.