Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Halt Sequence

Halt Sequence

Scheduled Pinned Locked Moved Visual Basic
helpquestioncsharpcom
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Red Sunday
    wrote on last edited by
    #1

    I'm trying to find a safe way to put a delay of 4 seconds in my code in VB 6.0 (NOT .NET). This is the code I have: Public Sub Wait() i As Integer Halt = 4 Dim LTime LTime = Timer() While Timer() - LTime < Halt i = 1 Wend End Sub This works great except for one problem. If I am running a form, press a button that calls this function, and then close the form before this function is completed, the visual of the button is corrupted. Basically, when the draw window is called (IE with a form.show call), the button shows through to the background and saves that image at its interface. IE If I have a word doc behind it, close the form with wait in progress, and form.show the form, it will bleed through with the button with whatever text is in the box of the button. How do I fix this?:confused: Thank you, Red Sunday ----------------- http://www.zachcalvert.com

    D F 2 Replies Last reply
    0
    • R Red Sunday

      I'm trying to find a safe way to put a delay of 4 seconds in my code in VB 6.0 (NOT .NET). This is the code I have: Public Sub Wait() i As Integer Halt = 4 Dim LTime LTime = Timer() While Timer() - LTime < Halt i = 1 Wend End Sub This works great except for one problem. If I am running a form, press a button that calls this function, and then close the form before this function is completed, the visual of the button is corrupted. Basically, when the draw window is called (IE with a form.show call), the button shows through to the background and saves that image at its interface. IE If I have a word doc behind it, close the form with wait in progress, and form.show the form, it will bleed through with the button with whatever text is in the box of the button. How do I fix this?:confused: Thank you, Red Sunday ----------------- http://www.zachcalvert.com

      D Offline
      D Offline
      Dennis C Dietrich
      wrote on last edited by
      #2

      Hi Red! I'm trying to find a safe way to put a delay of 4 seconds in my code in VB 6.0 (NOT .NET). First, don't use While...Wend to loop. Use a Do loop instead (see also How to Use Looping Structures in Visual Basic for Applications[^]). Second, don't use a loop at all. You can use Task-Manager to quickly find out that your loop will lead to 100% CPU usage. Use the API function Sleep instead.

      Option Explicit
      Public Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Integer)

      Public Sub Wait()
      Sleep 4000
      End Sub

      You can find more about Sleep and an API function called SetWaitableTimer (which might solve your re-draw problem) in the article How To Use SetWaitableTimer With Visual Basic[^]. Best regards Dennis

      1 Reply Last reply
      0
      • R Red Sunday

        I'm trying to find a safe way to put a delay of 4 seconds in my code in VB 6.0 (NOT .NET). This is the code I have: Public Sub Wait() i As Integer Halt = 4 Dim LTime LTime = Timer() While Timer() - LTime < Halt i = 1 Wend End Sub This works great except for one problem. If I am running a form, press a button that calls this function, and then close the form before this function is completed, the visual of the button is corrupted. Basically, when the draw window is called (IE with a form.show call), the button shows through to the background and saves that image at its interface. IE If I have a word doc behind it, close the form with wait in progress, and form.show the form, it will bleed through with the button with whatever text is in the box of the button. How do I fix this?:confused: Thank you, Red Sunday ----------------- http://www.zachcalvert.com

        F Offline
        F Offline
        Fade Amit BS
        wrote on last edited by
        #3

        depending on what you are trying to do, there are two main options: 1. Causing the Code to completly halt can be done by using the Sleep method (i saw you got a got overview of it) or by looping like you did BUT - add a DoEvents() call inside the loop, this will allow the window to redraw this approach of halting is not very safe to begin with, especially in VB6 that runs EVERYTHING on a single thread. you might want to try these two approachs: 2. Timer based halt. Create a timer object, and set it to start timing you in the 'Wait' method handle the timer's "Timer" event, in the hanlding sub a. disable the timer b. call a method to continue the operation there are additional ways to achieve this, but i think this will get you going Fade (Amit BS)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups