VB6: delay(100)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kuit_been

    #1

    VB6: delay(100)

    Searched on google, but without any succes.
    I need a function where I can define how long the PC has to wait until it
    executes its next command.

    I know that it is possible with a timer, but that gives some complications.
    A timer goes through his commands & then waits 100ms before he goes through
    his commands again, but if you call sth at the end of the timer, at first
    time he goes through it, he won't wait for 100ms.

    I found a function on the internet (kernel function: sleep 100), but in that
    case, it waited 100 mseconds BEFORE doing anything:
    txtInfo.text = "before sleep"
    sleep 100
    txtInfo2.text = "after sleep"
    --> result = that it waits 100 ms and THEN it fills the 2 textboxes, even
    the one that stands above the sleep command!

    I found a function delay(100) in a dll: port.dll: that is to control the lpt
    port, but that dll only works in win98, not in NT or XP. When I use the
    function out of that dll, the PC hangs a while & I don't think any code is
    executed then...


    If anyone knows any command like I need, it would be wonderfull!
    I need to write several data to the lpt port & after each command and data
    send, has to wait 100ms, so I have to call that function more than once on
    different places...

    Big thanks in advance!




  • thfc1961

    #2
    Re: delay(100)

    try this. sleep value is miliseconds so 1000 for 1 second.


    Public Declare Sub Sleep Lib "kernel32" (ByVal
    dwMilliseconds As Long)


    Sleep(1000)


    "Kuit_been" <nas#at#hotmail .com> wrote in message
    news:404ca084$0 $1925$ba620e4c@ news.skynet.be. ..[color=blue]
    > Searched on google, but without any succes.
    > I need a function where I can define how long the PC has to wait until it
    > executes its next command.
    >
    > I know that it is possible with a timer, but that gives some[/color]
    complications.[color=blue]
    > A timer goes through his commands & then waits 100ms before he goes[/color]
    through[color=blue]
    > his commands again, but if you call sth at the end of the timer, at first
    > time he goes through it, he won't wait for 100ms.
    >
    > I found a function on the internet (kernel function: sleep 100), but in[/color]
    that[color=blue]
    > case, it waited 100 mseconds BEFORE doing anything:
    > txtInfo.text = "before sleep"
    > sleep 100
    > txtInfo2.text = "after sleep"
    > --> result = that it waits 100 ms and THEN it fills the 2 textboxes, even
    > the one that stands above the sleep command!
    >
    > I found a function delay(100) in a dll: port.dll: that is to control the[/color]
    lpt[color=blue]
    > port, but that dll only works in win98, not in NT or XP. When I use the
    > function out of that dll, the PC hangs a while & I don't think any code is
    > executed then...
    >
    >
    > If anyone knows any command like I need, it would be wonderfull!
    > I need to write several data to the lpt port & after each command and data
    > send, has to wait 100ms, so I have to call that function more than once on
    > different places...
    >
    > Big thanks in advance!
    >
    >
    >
    >[/color]


    Comment

    • Steve Gerrard

      #3
      Re: delay(100)


      "Kuit_been" <nas#at#hotmail .com> wrote in message
      news:404ca084$0 $1925$ba620e4c@ news.skynet.be. ..[color=blue]
      > I found a function on the internet (kernel function: sleep 100), but[/color]
      in that[color=blue]
      > case, it waited 100 mseconds BEFORE doing anything:
      > txtInfo.text = "before sleep"
      > sleep 100
      > txtInfo2.text = "after sleep"
      > --> result = that it waits 100 ms and THEN it fills the 2 textboxes,[/color]
      even[color=blue]
      > the one that stands above the sleep command!
      >[/color]

      The code line before the sleep did execute before the sleep, but the
      display update it triggered did not.
      You can force the screen update with DoEvents or Refresh:
      txtInfo.text = "before sleep"
      DoEvents
      sleep 100
      txtinfo2.text = "after sleep"



      Comment

      • J French

        #4
        Re: VB6: delay(100)

        On Mon, 8 Mar 2004 17:35:17 +0100, "Kuit_been" <nas#at#hotmail .com>
        wrote:
        [color=blue]
        >Searched on google, but without any succes.
        >I need a function where I can define how long the PC has to wait until it
        >executes its next command.
        >
        >I know that it is possible with a timer, but that gives some complications.
        >A timer goes through his commands & then waits 100ms before he goes through
        >his commands again, but if you call sth at the end of the timer, at first
        >time he goes through it, he won't wait for 100ms.
        >
        >I found a function on the internet (kernel function: sleep 100), but in that
        >case, it waited 100 mseconds BEFORE doing anything:
        > txtInfo.text = "before sleep"
        > sleep 100
        > txtInfo2.text = "after sleep"
        >--> result = that it waits 100 ms and THEN it fills the 2 textboxes, even
        >the one that stands above the sleep command![/color]

        It is /not/ waiting 100ms before doing anything

        txtInfo.text = "before sleep"
        That generates a Windows message that will update the contents of
        txtInfo
        - but only when you let your App process it's message queue
        - and since you are ungenerously hogging the current thread's
        attention, it cannot process the message queue until you release it.

        Try:
        txtInfo.text = "before sleep"
        DoEvents ' <--- process message queue
        sleep 100
        txtInfo2.text = "after sleep"

        That will behave entirely differently

        Comment

        Working...