944,085 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2033
  • C RSS
Mar 28th, 2005
0

help with "disabling" a button

Expand Post »
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.

  1.  
  2. void CLab10Dlg::OnEnterDataButton()
  3. {
  4. // TODO: Add your control notification handler code here
  5. GetDlgItemText(IDC_ROW_NUM, m_row_num);
  6. GetDlgItemText(IDC_COL_NUM, m_col_num);
  7. GetDlgItemText(IDC_DATA, m_data);
  8. int row_num = atoi((LPCTSTR)m_row_num);
  9. int col_num = atoi((LPCTSTR)m_col_num);
  10. int data = atoi((LPCTSTR)m_data);
  11. int i;
  12. if(i < num_rows_cols)
  13. {
  14. magic_array[row_num-1][col_num-1] = data;
  15. i++;
  16. }
  17. if(i >= num_rows_cols)
  18. m_enter_data_button.EnableWindow(false);
  19.  
  20. }
and when I initialize "i" to zero, i get the error message:
error C2252: 'i' : pure specifier can only be specified for functions
Similar Threads
Reputation Points: 11
Solved Threads: 0
Light Poster
blackdove is offline Offline
46 posts
since Feb 2005
Mar 28th, 2005
0

Re: help with "disabling" a button

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

Edit: My apologies I didn't see the statement under your code.
Reputation Points: 11
Solved Threads: 1
Light Poster
Auto is offline Offline
33 posts
since Mar 2005
Mar 28th, 2005
0

Re: help with "disabling" a button

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.
Reputation Points: 11
Solved Threads: 0
Light Poster
blackdove is offline Offline
46 posts
since Feb 2005
Mar 28th, 2005
0

Re: help with "disabling" a button

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;
Reputation Points: 11
Solved Threads: 1
Light Poster
Auto is offline Offline
33 posts
since Mar 2005
Mar 28th, 2005
0

Re: help with "disabling" a button

okay i'll try that thx.
Reputation Points: 11
Solved Threads: 0
Light Poster
blackdove is offline Offline
46 posts
since Feb 2005
Mar 29th, 2005
0

Re: help with "disabling" a button

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.
Reputation Points: 11
Solved Threads: 0
Light Poster
blackdove is offline Offline
46 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: a problem wilth C program
Next Thread in C Forum Timeline: Nested template class





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC