Thread: how to make a loading bar??

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    6

    Question how to make a loading bar??

    I need to put in a loading bar to my assignment program so that it will look nicer.
    Anyone knows how to make it??

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    And which of the many different kinds of operating systems, compilers and displays are we supposed to assume from your terse post?

    > Anyone knows how to make it??
    How To Ask Questions The Smart Way
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Is it a gui? a console?

    In any case the progress value can be mapped to the 'progress bar' area with something like:

    Code:
           progress = i / 100      //  ' i ' being your loop counter value 
            progressBar.fillWidth = progress * progressBar.width
    Last edited by rogster001; 07-05-2012 at 08:10 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  4. #4
    Registered User
    Join Date
    Jul 2012
    Posts
    6
    salem, currently I am using Windows 7 and c ++

  5. #5
    Registered User
    Join Date
    Jul 2012
    Posts
    6
    rogster001, can u give me an example of full program of that ?
    I am just a beginner and cant get what u mean ><

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You should answer these questions:
    Quote Originally Posted by Salem
    And which of the many different kinds of operating systems, compilers and displays are we supposed to assume from your terse post?
    Quote Originally Posted by rogster001
    Is it a gui? a console?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > salem, currently I am using Windows 7 and c ++
    C++ covers a multitude of sins from TurboC++ through to Visual Studio 20xx (whatever the latest number is).

    Which compiler (name and version) are you using?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Jul 2012
    Posts
    6
    I am using microsoft visual studio 2010
    Where can i get know which version i am using?

  9. #9
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    I am going to assume you are doing a simple console output.

    The most simple way to express progress is a numeric percentage eh?

    so if your program has to loop 100,000 times before it is finished then
    use the counter value eg 75 loops so far to obtain a percentage and output it
    with a message saying like "progress is... X% of completed"

    your problem then only becomes either repeatedly clearing the screen to keep your display
    in place, or using gotoxy functions to just write the percentage as it increases

    for a progress 'bar'
    Why not consider just outputting a simple ' # ' symbol ? every 100 iterations of your loop,
    so then you get a nice little effect
    ##########
    done!

    But consider this - it is likely your program, assuming it only performs a basic function, will execute so fast that you will not even see the progress effect anyway, you will just hit run and then see " 100% " immediately
    and you would have to artificially slow your program down to view it increasing
    Last edited by rogster001; 07-05-2012 at 09:06 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  10. #10
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by chan View Post
    rogster001, can u give me an example of full program of that ?
    I am just a beginner and cant get what u mean ><
    Some advice - perhaps you should put this project off until you learn the language well enough to fully understand how to implement a progress bar. If you're completely at a loss for how to implement such a function, then that probably means you're not ready to undertake such a challenge.

    On the other hand, if you're experienced enough to attempt it - even if you can't get it to work right - and provide the code you've tried so far, you'll receive much better feedback from the contributors of this forum.

  11. #11
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    p.s. you could use "\r" escape character to keep your progress indicator, or progress value in place as a quick workaround -
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  12. #12
    Registered User
    Join Date
    Jul 2012
    Posts
    6
    Quote Originally Posted by rogster001 View Post
    I am going to assume you are doing a simple console output.

    The most simple way to express progress is a numeric percentage eh?

    so if your program has to loop 100,000 times before it is finished then
    use the counter value eg 75 loops so far to obtain a percentage and output it
    with a message saying like "progress is... X% of completed"

    your problem then only becomes either repeatedly clearing the screen to keep your display
    in place, or using gotoxy functions to just write the percentage as it increases

    for a progress 'bar'
    Why not consider just outputting a simple ' # ' symbol ? every 100 iterations of your loop,
    so then you get a nice little effect
    ##########
    done!

    But consider this - it is likely your program, assuming it only performs a basic function, will execute so fast that you will not even see the progress effect anyway, you will just hit run and then see " 100% " immediately
    and you would have to artificially slow your program down to view it increasing
    Thanks Rogster001
    I will try to code it ^^

  13. #13
    Registered User
    Join Date
    Jul 2012
    Posts
    6
    Quote Originally Posted by Matticus View Post
    Some advice - perhaps you should put this project off until you learn the language well enough to fully understand how to implement a progress bar. If you're completely at a loss for how to implement such a function, then that probably means you're not ready to undertake such a challenge.

    On the other hand, if you're experienced enough to attempt it - even if you can't get it to work right - and provide the code you've tried so far, you'll receive much better feedback from the contributors of this forum.
    Matticus~ thanks for your advise
    My lecturer said that he will teach this in this week but he did not.. so i just want to seek for some help before passing up my assignment ^^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-27-2011, 04:14 PM
  2. Establishing 'make clean' with GNU make
    By Jesdisciple in forum C Programming
    Replies: 9
    Last Post: 04-11-2009, 09:10 AM
  3. How would I make a c++ prgoram make a .exe file?
    By Rune Hunter in forum C++ Programming
    Replies: 9
    Last Post: 12-26-2004, 05:56 PM
  4. Make window in VB but make program in C/C++?
    By Boomba in forum Windows Programming
    Replies: 1
    Last Post: 06-23-2004, 12:29 AM
  5. Replies: 6
    Last Post: 04-20-2002, 06:35 PM