Results 1 to 18 of 18

Thread: A little "Pause" program

  1. #1

    Thread Starter
    Lively Member Patrice Bourdages's Avatar
    Join Date
    Jun 2000
    Location
    Quebec, Canada
    Posts
    83

    Question

    I'm stuck...

    I need to create a tiny program that will do the following:
    Receive a parameter (number of seconds) and "end" himself after that time has expired... I've looked into the timer stuff but I'm lost...

    Help Please... TIA

    Sincerely yours,

    Patrice B.
    Sincerely yours,

    Patrice B.
    Information System Analyst
    SAS 9.1.3, VB6 SP6, VB.Net 2003, SQL7.0/2000

  2. #2
    Guest
    Try:
    Code:
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    
    Private Sub Form_Load()
    
        'Get a time to pause
        Retval = InputBox("Enter number of milliseconds")
        Start = GetTickCount
        
        'Pause for that amount of milliseconds
        Do While GetTickCount < Start + Retval
            DoEvents
        Loop
        
        'End the program
        MsgBox ("Program is now ending")
        End
        
    End Sub

  3. #3

    Thread Starter
    Lively Member Patrice Bourdages's Avatar
    Join Date
    Jun 2000
    Location
    Quebec, Canada
    Posts
    83

    Wink

    Sounds very good...

    I forgot to mention that the parameter would be received from the OS like the following

    c:\PauseProgram 15

    That would run for 15 seconds...

    Where is the change??? How do I adapt???

    TIA, Patrice :-)
    Sincerely yours,

    Patrice B.
    Information System Analyst
    SAS 9.1.3, VB6 SP6, VB.Net 2003, SQL7.0/2000

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Megatron: I don't think that'll work if you don't use CInt(RetVal)
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    ---modTimer.Bas---
    Option Explicit
    'GetTickCount Declared here

    Sub Main()
    Dim MyTime
    Dim Start
    MyTime = Cint(Trim(Command$))
    Do While GetTickCount < Start + MyTime
    DoEvents
    Loop
    'code here for whatever you want to do after the time
    End
    End Sub
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6

    Thread Starter
    Lively Member Patrice Bourdages's Avatar
    Join Date
    Jun 2000
    Location
    Quebec, Canada
    Posts
    83

    Talking

    Thank you very much all of you guys...

    Really appreciate it...

    Patrice B.
    Sincerely yours,

    Patrice B.
    Information System Analyst
    SAS 9.1.3, VB6 SP6, VB.Net 2003, SQL7.0/2000

  7. #7
    Guest
    Sastraxi: Although it's improper, you can omit the CInt() and it will still work.

  8. #8
    New Member
    Join Date
    Jun 2000
    Posts
    11
    The pause function posted by Megatron works, and is actually a similar solution of mine for a program that I made. My program executes VB Scripts and I needed a way to pause for a certain period of time in the VB Script, and using the Timer control just wasn't an option.
    The only problem with this function is that it uses up all processor resources and if it has to do that for more than half an hour, it could really heat up the processor. The only other way I found to pause for a time period was to use the "Sleep" API. But this function pauses the whole thread, which is an unwelcome side effect since the user can no longer interact with the application.

    Any other ideas?
    Alex Begey
    CrystalDev
    VB6 SP4

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    To pause your app, you should remove the doevents statement, since it could allow any events to fire and run during the loop. Sleep does that as well.

    But i think what you meant with pause is just to have a dealy to the code that follows.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10
    New Member
    Join Date
    Jun 2000
    Posts
    11

    Smile

    DoEvents makes the application process events such as mouse moves, clicks, and other form events. But when I use Sleep, it pauses the whole thread. I'm using the Sleep API in VBScript (by referencing it from a class), but when it starts, the whole application freezes until the Sleep timer finishes. What I'm looking for is a sort-of a "DoEvents" in my VBScript that pauses the (VBScript) program and then also allows me to interact with the host application (of the VBScript).

    I don't think using Sleep in my VBScripts is a good idea, since my programs pause for more than a couple seconds. But using the "Do-Loop" approach isn't good either, since it boggles up all processor power.

    Any other ideas?
    Alex Begey
    CrystalDev
    VB6 SP4

  11. #11
    Guest
    Kedaman, if you do not include DoEvents, the program can freeze.

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    It won't freeze your program, it's the event's that don't get fired.

    Search for Settimer, Sashko

    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  13. #13

    Thread Starter
    Lively Member Patrice Bourdages's Avatar
    Join Date
    Jun 2000
    Location
    Quebec, Canada
    Posts
    83

    Unhappy

    It seems to work very well... At least internally.

    But when added to a batch file, it doesn't pause "the batch file". The programs runs in the background and the batch file only stops for a few milliseconds (the time required to launch the program).

    Does it have anything to do with the "follow up" you guys have been doing?

    TIA

    Patrice
    Sincerely yours,

    Patrice B.
    Information System Analyst
    SAS 9.1.3, VB6 SP6, VB.Net 2003, SQL7.0/2000

  14. #14
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    A batch file doesn't wait for a Windows EXE to stop executing before going on to the next command.

  15. #15

    Thread Starter
    Lively Member Patrice Bourdages's Avatar
    Join Date
    Jun 2000
    Location
    Quebec, Canada
    Posts
    83
    Even I try to make this executable something like "modal"?
    Sincerely yours,

    Patrice B.
    Information System Analyst
    SAS 9.1.3, VB6 SP6, VB.Net 2003, SQL7.0/2000

  16. #16
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    It doesn't matter. A DOS batch file and a Win32 app is running on different Virtual Machines.

  17. #17
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Even Systemmodal won't stop any app to run, but will prevent windows to recieve messages.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  18. #18

    Thread Starter
    Lively Member Patrice Bourdages's Avatar
    Join Date
    Jun 2000
    Location
    Quebec, Canada
    Posts
    83

    Smile

    Thank you very much for the reply... :-)

    Learning new stuff everyday just by reading post from all the guys on this forum...

    It's great...
    Sincerely yours,

    Patrice B.
    Information System Analyst
    SAS 9.1.3, VB6 SP6, VB.Net 2003, SQL7.0/2000

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