Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Display Timing Problem (VB 6.0)

    I am attempting to display a text string in a text or label box for a programmable (but short) period upon clicking a command button. In the On_Click event , I set the string into the box, then use a Do loop to create a delay, then replace the string. Example:

    LabelName.Caption = "START"
    Counter = large_number
    Do While Counter > 0
    Counter = Counter -1
    Loop
    LabelName.Caption = "END"

    However, the display never changes from the default caption to START, but after the delay it displays END. If I comment out the DO loop and final caption change, then it displays START. Is there some timing limitation here regarding updating the display?

    Also, is there a command in VB for creating a delay (not the Timer) to use instead of the Do loop? For example something like Wait(msec) where msec is the number of milliseconds to pause before continuing with the next statement.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Display Timing Problem (VB 6.0)

    Call the .Repaint method when you change the label. That has worked for me.

    To wait for a while, there is a WinAPI call, something like Sleep or Wait. I could dig for it, but I bet someone knows off the top of her/his head.

  3. #3
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Display Timing Problem (VB 6.0)

    Thanks,

    I had problems with Repaint, but Refresh works like a charm.

    I suspected that a Wait or similar function was out there somewhere. Being very new to VB programming I don't understand what a WinAPI call is, but I trust that someone will inform me.

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Display Timing Problem (VB 6.0)

    WinAPI calls are calls into the Windows Applications Programming Interface. Instead of talking to Windows *through* the VB wrapper, you're talking directly to the Windows interace with an API call. The SleepEx function causes the thread to enter a wait state until something occurs to terminate that state or the specified interval elapses. Here's the declaration:

    Private Declare Function SleepEx Lib "kernel32" (ByVal dwMilliseconds As Long, ByVal bAlertable As Long) As Long


    You call it like this:

    SleepEx 2000, False

    Where the argument is the miliseconds you want to pause the thread.
    Charlotte

  5. #5
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Display Timing Problem (VB 6.0)

    That works perfectly.

    Thanks again Charlotte. You are a real life saver.

Posting Permissions

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