| | |
Show Progress in % problem
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 173
Reputation:
Solved Threads: 1
I am stuck in a problem where I should show a progress in % in a label. I have manage this code and think this should work but the label doesn´t update the % value it only shows "Progress... 0 %".
Is there anything I perheps should add to update the value in the label in realtime.
I have instead of:
Application:: DoEvents()
Also tried this without success.
Is there anything I perheps should add to update the value in the label in realtime.
I have instead of:
Application:: DoEvents()
Also tried this without success.
C++ Syntax (Toggle Plain Text)
this->Update(); this->ResumeLayout(true);
C++ Syntax (Toggle Plain Text)
//Show progress in % double ShowProgress = 0; for( int i = 0; i < 2231; ++i ) { Thread::Sleep(10); ShowProgress = (i / 2231) * 100; label1->Text = "Progress... " + Convert::ToString(ShowProgress) + " %" ; Application::DoEvents(); //Update Form }
Last edited by Lukezzz; Nov 26th, 2008 at 8:53 pm.
•
•
Join Date: Aug 2008
Posts: 206
Reputation:
Solved Threads: 31
You are making the mistake of assuming that integer division yields a floating point result - it doesn't: it yields an integer result and integers can't represent fractions.
In your code i/2231 is an integer division, and yields an integer result by rounding towards zero (hence always yields zero if i is in the range [0,2231) ).
You need to force the division i/2231 to be a floating point division to get the result you expect. For example; or
In your code i/2231 is an integer division, and yields an integer result by rounding towards zero (hence always yields zero if i is in the range [0,2231) ).
You need to force the division i/2231 to be a floating point division to get the result you expect. For example;
ShowProgress = ((double)i / 2231) * 100;ShowProgress = (i / 2231.0) * 100;![]() |
Similar Threads
- Problem with timer (urgent) (Visual Basic 4 / 5 / 6)
- Bad adware problem (Viruses, Spyware and other Nasties)
- huge annoying antispylab problem requiring help (Viruses, Spyware and other Nasties)
- recurring spyware/virus problem.. girls.exe etc... (Viruses, Spyware and other Nasties)
- Help, really strange problem (Viruses, Spyware and other Nasties)
- Yet another antispylab problem (Viruses, Spyware and other Nasties)
- problem installing windowsxp updates (Windows NT / 2000 / XP)
- Minor problem with some script... (C)
- Icon and Thumbnail Display Problem (Windows NT / 2000 / XP)
- Problems with IE version 6.0 (Web Browsers)
Other Threads in the C++ Forum
- Previous Thread: cout types
- Next Thread: Blackjack problem.
Views: 337 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






