473,809 Members | 2,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble with Algorithm?

50 New Member
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(Syst em::Object * sender, System::EventAr gs * 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 919

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

Similar topics

3
3773
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 sit on top of them. I am developing a solver and need a pause between each move the algorithm makes. I know from my past experience that you have to use something along the lines of :-
3
1500
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
2707
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, basically). This vector is partitioned each time the file list was rebuilt into paths which are directories and paths which are not. The directories comes first.
113
12362
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 algorithm work with strings that may or may not be unicode 3) Number of bytes back must either be <= number of _TCHARs in * sizeof(_TCHAR), or the relation between output size and input size can be calculated simply. Has to take into account the...
3
1684
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 straightforward: *PSEUDOCODE* for i=1 thru ( Container.Length-1 ) for j=i+1 thru ( Container.Length-1 ) if ( TextBox==TextBox )
2
7299
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 as possible from users, so we encourage you to test the algorithm and send us your opinion. We would also like to receive enhancements and new versions of the algorithm, developed in other source languages and platforms. Our idea on developing...
0
2973
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 so interest about this encoding algorithms. because our group is going to do a project under the ITU-T Recommendation X.891. this is named as fast infoset. this is an open source project in c language. there is an implementation in java which by...
10
1183
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 to get it to break where I want it to, i.e., when the sum equals the limit as closely as the precision allows? Here's what I have:
1
1491
by: Nick Keighley | last post by:
Hi, this is cut from a larger program. <code> #include <algorithm> #include <vector>
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10643
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10378
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10391
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.