| | |
labelBox
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 517
Reputation:
Solved Threads: 1
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
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
C++ Syntax (Toggle Plain Text)
MessageBox::Show("Display this");
C++ Syntax (Toggle Plain Text)
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'; } }
Last edited by Jennifer84; Feb 22nd, 2008 at 2:52 pm.
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?
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?
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
•
•
Join Date: Feb 2008
Posts: 517
Reputation:
Solved Threads: 1
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 ?
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 ?
C++ Syntax (Toggle Plain Text)
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?
•
•
Join Date: Feb 2008
Posts: 517
Reputation:
Solved Threads: 1
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 ?
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 ?
C++ Syntax (Toggle Plain Text)
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'; } }
Last edited by Jennifer84; Feb 22nd, 2008 at 6:26 pm.
![]() |
Similar Threads
- i want to send labelbox value with redirect page (ASP.NET)
- i want to send labelbox value with redirect page (VB.NET)
Other Threads in the C++ Forum
- Previous Thread: Problems with Assignment once again
- Next Thread: Stacks, Queues, and a Maze??
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game generator getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






