Connecting Tech Pros Worldwide Forums | Help | Site Map

Trouble with Algorithm?

Member
 
Join Date: Jul 2007
Posts: 47
#1: Sep 11 '07
This code makes sense to me, I'm just having trouble trying to understand why it doesn't work correctly. This is a GUI APP. When the Play button is Clicked, the play_Click(System::Object * sender, System::EventArgs * e) function is called, it is suppose to make the Play button dissapear and the Pause Button Appear as soon as the Play button is clicked. I don't know why it calls the keystrokes function then goes through the while loop continuously without ever displaying the Pause Button, instead of making the Play dissapear and the Pause appear then goto the keystrokes function which will finally go through the while loop. I also had conditions where it would go through the file once, then stop, then display the Pause Button.

My objective is to Play, Pause whenever the user wants. When Play is clicked, the Play button should dissapear and the Pause Button should appear. When the Pause button is clicked, the pause button should dissapear and the Play button should appear. That way the user can Play and Pause the file iteration at ANY point in time.


Expand|Select|Wrap|Line Numbers
  1.  
  2. private: System::Void keystrokes(System::Object *  sender, System::EventArgs *  e)//, char *array)
  3.          {//actual key presses depending on the characters read
  4.  
  5.             char array[255];
  6.  
  7.             ifstream in;
  8.  
  9.             in.open("c:\\write.txt", ios::in);
  10.  
  11.  
  12.             if(!in)
  13.             {
  14.                 richTextBox1->AppendText("\nCannot open input file.\n");
  15.                 return;
  16.             }
  17.  
  18.             while(in) //&& keystrokeFlag == true)
  19.             {
  20.                 if(playFlag == false)
  21.                 {
  22.                     richTextBox1->AppendText("\nBreak\n");
  23.                     break;
  24.                 }
  25.  
  26.                 richTextBox1->AppendText("\nGetline\n");
  27.                 in.getline(array, 4); //delim defaults to '\n'
  28.  
  29.                 richTextBox1->AppendText("\nPush Keystrokes\n");
  30.                 pushKeystrokes(sender, e, array);
  31.  
  32.                 richTextBox1->AppendText("\nCheck Status\n");
  33.                 checkStatus(sender, e);
  34.  
  35.                 richTextBox1->AppendText("\nSleep Timer\n");
  36.                 System::Threading::Thread::Sleep(100);
  37.  
  38.                 if(in.eof())
  39.                 {
  40.                     richTextBox1->AppendText("\nEND OF FILE\n");
  41.                     in.clear(); //clear the flags (in.seekg() will not work properly without this function call)
  42.                     in.seekg(0, ios::beg); //infinite loop work on this tomorrow
  43.                 }
  44.  
  45.             }
  46.             in.close(); //close document
  47.          }
  48.  
  49. private: System::Void checkStatus(System::Object *  sender, System::EventArgs *  e)
  50.          { 
  51.             richTextBox1->SelectionColor = Color::LimeGreen; //color indication testing purposes
  52.             if(play->Visible == true)
  53.             {
  54.                 richTextBox1->AppendText("FALSE\n");
  55.                 playFlag = false;
  56.             }
  57.             if(play->Visible == false)
  58.             {
  59.                 richTextBox1->AppendText("TRUE\n");
  60.                 playFlag = true;
  61.             }
  62.          }
  63.  
  64. private: System::Void play_Click(System::Object *  sender, System::EventArgs *  e)
  65.          {
  66.             play->Visible = false;
  67.             pause->Visible = true;
  68.  
  69.             keystrokes(sender, e);
  70.          }
  71.  
  72. private: System::Void pause_Click(System::Object *  sender, System::EventArgs *  e)
  73.          {    
  74.             pause->Visible = false;
  75.             play->Visible = true;
  76.  
  77.             keystrokes(sender, e);
  78.          }
  79.  
  80.  
Reply