I have a wondering here. This code I have below is working great except of one thing that doesn´t make sense to me.
I use a while-loop inside a for-loop as seen.
The for-loop is counting from 1-49 and for each count the while-loop will read a .txt file and put some info to a file.
Notice now in my code in the for-loop that I have put "Display this" to a label on my form.

This should be shown for the first count in the foor-loop wich is 1 ?
What happens in this code is that "Display this" will be shown First when the count is ready, wich then is count = 49.
Why is this happening. It should be shown directly and not in the end of the loop ?

HowEver if I put this message box in the same place instead of "CurrentSymbol" then it will
Display a new messagebox for each count wich meens 49 MessageBoxes

MessageBox::Show("Display this");
std::string Line;
ofstream MainFile;
MainFile.open ("Main.txt");


	for (int count= 1; count < (50); count++)
	{ 
		
		CurrentSymbol->Text = "Display this";
				
	
		ifstream File ("DGD.txt");
		while	(    getline(File, Line, '\n')  )           		
		{
		
			MainFile << "Hello" << ',' << "Hello2" << '\n';

		}


	}

Here's what I see should be occurring:
The outer loop runs 49 iterations. In each it:
puts the text "Display this" to the text of CurrentSymbol (which I don't know what happens there)
the file DGD.txt will be opened, the while loop then reads it line by line to the end. As each line is read, "Hello,Hello2\n" is written to the output file.

But wait, there's less. Whe the for loop executes second time, the input file hasn't been closed or cleared, so nothing gets read in. Since there's nothing to read, nothing more goes to the output file.
This whole loop can spin so fast, you may not see the "Display This" being updated 48 times.

What is it you're really trying to do?

This is just an simple example. The thing is that later the foor-loop will read 49 different files, with the different names. So I will catch up each of these name in the labelBox.

This meens that I visually can se on the form wich File that is readed for the specific moment. This is why I am doing this.

The strange thing is that if you exchange "CurrentSymbol" to the MessageBox then it will work, The messagebox will execute before the while-loop takes in for the first time but strange that CurrenSymbol dont behave in the same way. I dont know if this has anything with that I close the file because this happen before I actually beginning with the while-loop ?

CurrentSymbol->Text = "Display this";
			
MessageBox::Show("Display this");

Here's what I see should be occurring:
The outer loop runs 49 iterations. In each it:
puts the text "Display this" to the text of CurrentSymbol (which I don't know what happens there)
the file DGD.txt will be opened, the while loop then reads it line by line to the end. As each line is read, "Hello,Hello2\n" is written to the output file.

But wait, there's less. Whe the for loop executes second time, the input file hasn't been closed or cleared, so nothing gets read in. Since there's nothing to read, nothing more goes to the output file.
This whole loop can spin so fast, you may not see the "Display This" being updated 48 times.

What is it you're really trying to do?

I have trried to Invalidate() the CurrentSymbol wich is my label right after the "Display this" was put to the label but this didn´t work.
However I think I have to use that in a way togehter with somthing like SendMessage(WM_PAINT) but I am not sure if this is the way or how to do this though ?

std::string Line;
	ofstream MainFile;
	MainFile.open ("Main.txt");


	for (int out = 1; out < (10); out++)
	{ 
		
	CurrentSymbol->Text = "Display this";
	CurrentSymbol->Invalidate();		
	

	ifstream File ("DGD.txt");
		while	(    getline(File, Line, '\n')  )           		
		{
		
			MainFile << "Hello" << ',' << "Hello2" << '\n';

		}


	}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.