Results 1 to 6 of 6

Thread: Data type conversion for a progress bar

  1. #1

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    Question Data type conversion for a progress bar

    I have a variant Ė varDuration. It looks like 00:03:21. (Donít get hung up on the particular value. I can display this as 03:21, or maybe as 3:21.
    And yes, it does represent minutes and seconds. I need to sync this to a timer, and display the numbers as the seconds change. i.e. 3:21 then 3:20 then 3:19 etc. all the way to zero. I know I canít do any math operations on a variant.

    Can anyone explain how I can do this?
    To make this more complicated, I have a progress bar on my form. The bar will go from a min value of 00:00 to a max value of 03:21 (or whatever the duration is). It will start at 0 and progress to the max value (3:21, or whatever). The progress moves from left to right. I want the max displayed value to decrease as the progress bar increases.

    Initially, I would like the high level concept of how I would do this. If I get bogged down this that, maybe I will ask for some detailed help.

    Thanks

  2. #2
    Frenzied Member
    Join Date
    Nov 2017
    Posts
    1,657

    Re: Data type conversion for a progress bar

    Ditch that variant variable and use an integer variable for hours, minutes, seconds. If you need to display it has hh:mm:ss then handle the display however you want.

    Then you can just use math to do everything you've described.

  3. #3

    Thread Starter
    Hyperactive Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    464

    Re: Data type conversion for a progress bar

    I can't change how I got the variant. I never heard of a quick way to convert the variant. I guess that means just parse the hh, nn, and ss into separate integers variables and do the hard math for the movement of the progress bar.

  4. #4
    Frenzied Member
    Join Date
    Nov 2017
    Posts
    1,657

    Re: Data type conversion for a progress bar

    Split it using the ":" as the delimiter. Make sure you handle situations where the hours are missing (11:33) vs when the hours are present (02:11:33)

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,825

    Re: Data type conversion for a progress bar

    Yeah, Variants have many uses but in general they should be avoided.

    Not as bad as using On Error Resume Next blindly, or even worse DoEvents() calls to write buzz loops to avoid proper event handling.

    You can use TimeSerial() to convert Integer to Date type, then use Format$().


    Here's a demo with some other fluff. For example the compiled EXE will use the updated Common Controls 6 ProgressBar, though you normally won't see it in debug runs done in the IDE.

    Use the menu to run, pause, stop, or "error" the progress.
    Attached Files Attached Files

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,825

    Re: Data type conversion for a progress bar

    Well there is always:

    Code:
        Dim CrappyVariant As Variant
        Dim Seconds As Long 'Integer risks overflow above about 9 hours.
    
        CrappyVariant = "02:11:33"
        Seconds = DateDiff("s", #12:00:00 AM#, CDate(CrappyVariant))
        Debug.Print Seconds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width