Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

status bars in a vb program

Options
  • 02-06-2002 10:55pm
    #1
    Registered Users Posts: 30


    Does anyone know if there is a way to get a status bar running,in the foreground, with your program to show you how much time is left. like the kind you get when installing something?
    Also wondering if you can set up a timer to tell you how long your program has been running.
    I have a little sub in at the start to check how many comparisons that the program has to do and then it starts counting down but I am wondering if there is an easier and faster way?


Comments

  • Registered Users Posts: 1,842 ✭✭✭phaxx


    For the time running, you can use a timer, set the interval to 1000 and have that timer increment a variable, and that will be how many seconds it's been running for.

    For the progress bar, press ctrl-T, select "Microsoft Windows Common Controls" and then you can add the "progress bar" control from your, er, tools window or whatever it's called.

    As for the comparisons thing, I can't tell, I'd need to see the code.


  • Registered Users Posts: 30 tele


    Its kinda different, the project I am working on is in excel so the vb is a bit different. Its my first time doing stuff like this in excel. The program takes about 9-10 mins to run, it basically compares two pretty big sheets nad manipulates the info. I can't find anything to do with timers or "Microsoft Windows Common Controls" in the Excel form of vb. I thought they should be the same(vb and excel-vb is what i mean). If I am not making much sence its probably because I am just finishing my first 12 hr shift of thew week. thanks phaxx for the tips though I messed around with them a bit in the real vb mode.


  • Registered Users Posts: 1,842 ✭✭✭phaxx


    Right click the toolbar box when you have a form open, ms windows common controls are in that list. (Yes, that's vbscript in excel)

    To do the time running, if there's no timer you can note the time when the app starts an then compare it to the current time whenever you need the time running displayed, but that's awkward and ugly.


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by phaxx
    To do the time running, if there's no timer you can note the time when the app starts an then compare it to the current time whenever you need the time running displayed, but that's awkward and ugly.

    I dunno if its that awkward.

    Id do an API call to getTickCount() at the start, and then when I want to find elapsed time, do another getTickCount, subtract the original value, and voila - elapsed time in milliseconds. (For extra brownie points, I would wrap this functionality into a tiny little COM object, which I could then re-use in all my projects).

    This, IMHO, is far and away the best way of handling elapsed time scenarios, and is generally accurate enough to be useful for optimisation timings in your code as well.

    From there, you can use elapsed time and % complete values (which you will have from knowing the total number of items, and the number of processed items) to estimate remaining time.

    As an aside - when running a "progress indicator" form like this, you should remember that screen updates are very very slow. IN other words - if you were to update the display after *each* cell has been checked (or whatever), you could increase your run-time by up to a factor of 10!!!

    Generally, for such things, I update the screen after every 100 items, or every 1% of the total, or every 5 seconds, or something like that. Speeds up execution time due to fewer screen refreshes, and often makes the screen refresh more useful.

    Hopefully that all makes sense to you :) If not - ask away, and Ill help you out. Ideally - show us some code you have, and describe whats not working, or what you want to do with it.

    Best of luck with it....

    jc


  • Registered Users Posts: 1,842 ✭✭✭phaxx


    Aaahh... ta bonkey.


  • Advertisement
  • Registered Users Posts: 30 tele


    Thanks fellas. Just started work so i'll give some of the stuff a go in a while.


  • Registered Users Posts: 30 tele


    Hey bonkey how do i use the getTickCount () thingy. I dont have MSDN help files yet so its kinda hard to find out stuff.
    I have the timer on the form, how do i use that.
    I am looking to set up a counter, say in a txt box that increments every second and then at the end maybe a message box saying Your PRogram took x seconds to run.
    Thanks for the help lads


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by tele
    Hey bonkey how do i use the getTickCount () thingy. I dont have MSDN help files yet so its kinda hard to find out stuff.

    Heh - you could look it up on the hinternet....msdn.microsoft.com

    But anyway.....I'll help you out, cause I'm nice like that....and I finished work early today.....

    I am looking to set up a counter, say in a txt box that increments every second and then at the end maybe a message box saying Your PRogram took x seconds to run.

    Dont use a timer. You dont need one, and its more hassle then its worth.

    Look at the module I include below. When your code starts, make a call to StartCounter.

    During the processing, make a call to GetElapsedTime to find out how much time has elapsed. You can update a textbox (or label) with this value...but like I said above, I'd do it every 10 or 100 items, as opposed to every one.

    Here's what I mean....
            StartCounter()
            For i = 0 To 10000
                ' do your work here
                If (i Mod 100) = 0 Then
                    elapsedTime = GetElapsedTime()
                    TextBox1.Text = CStr(i)
                    TextBox2.Text = CStr(elapsedTime)
                End If
            Next i
    

    i and elapsedTime are both of type Long, unless you use VB.NET where they would be Integer.

    Obviously, my loop is probably a bit simpler than yours, but this should show you the idea. If you want to test it out, then simply put something slow-ish instead of my work comment - perhaps something like : x = sqrt(1234567, and bobs your uncle.)

    Now - this used two custom-written methods - StartCounter and Elapsed Time. Here follows a VB.NET implementation of these. To convert to pre-.NET syntax should be easy enough...the only thing to watch out for is that you must change all type declarations from Integer to Long. There are some other syntax changes needed as well, but hey - I'm not doing all the work for you.

    This should give you an idea of how it can be done.

    Oh - because of the wonders of windows, you may need to refresh the display after updating the textboxes. You typically do this with me.refresh I think....

    Hope that helps...and here's the magic code.
    Module Module1
        Private startValue As Integer
    
        Declare Function GetTickCount Lib "kernel32.dll" () As Integer
    
        Public Function StartCounter() As Integer
            startValue = GetTickCount()
            Return startValue
        End Function
    
        Public Function GetElapsedTime() As Integer
            Dim currentValue As Integer
            Dim elapsedTime As Integer
    
            currentValue = GetTickCount()
            If currentValue < startValue Then
                elapsedTime = -1
            Else
                elapsedTime = currentValue - startValue
            End If
    
            Return elapsedTime
    
        End Function
    
    End Module
    

    jc


Advertisement