954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help with "disabling" a button

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

blackdove
Light Poster
46 posts since Feb 2005
Reputation Points: 11
Solved Threads: 0
 

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.

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


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

Auto
Light Poster
33 posts since Mar 2005
Reputation Points: 11
Solved Threads: 1
 

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.

blackdove
Light Poster
46 posts since Feb 2005
Reputation Points: 11
Solved Threads: 0
 

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 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;

Auto
Light Poster
33 posts since Mar 2005
Reputation Points: 11
Solved Threads: 1
 

okay i'll try that thx.

blackdove
Light Poster
46 posts since Feb 2005
Reputation Points: 11
Solved Threads: 0
 

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.

blackdove
Light Poster
46 posts since Feb 2005
Reputation Points: 11
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You