473,378 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Trouble with Algorithm?

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.  
Sep 11 '07 #1
0 902

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Lee Garrington | last post by:
Hello, Basically this is my problem. I am programming minesweeper in java. I have a panel in the background on which I draw all the mines/numbers etc. and then I have an array of buttons that...
3
by: Griff | last post by:
#include <iostream> using namespace std; #include <vector> #include <string> #include <fstream> #include <algorithm> template<class C>void PrintAll(C&v) {
2
by: Matthias Kaeppler | last post by:
Hello, I am having trouble getting std::equal_range to perform as I wish, and I can't find my error. Here's the situation: I have a vector of pointers to filesystem path objects (a file list,...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
3
by: 2obvious | last post by:
I have a DataGrid containing a TextBox control and a CustomValidator in each row. The CustomValidator fires a function that compares all TextBoxes for equality. The algorithm for comparison is...
2
by: Julio C. Hernandez Castro | last post by:
Dear all, We have just developped a new block cipher called Raiden, following a Feistel Network structure by means of genetic programming. Our intention now consists on getting as much feedback...
0
by: aruna | last post by:
hey guys i earlier had very valuable responses from you all for base64 encoding algorithm.so thank for that. so now i need your assistance to do a float encoding algorithm. you may wonder why i'm...
10
by: Dick Moores | last post by:
I'm writing a demo of the infinite series x**0/0! + x**1/1! + x**2/2! + x**3/3! + ... = e**x (x is non-negative) It works OK for many x, but for many the loop doesn't break. Is there a way...
1
by: Nick Keighley | last post by:
Hi, this is cut from a larger program. <code> #include <algorithm> #include <vector>
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.