-
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.
-
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
-
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 :-)
-
Megatron: I don't think that'll work if you don't use CInt(RetVal)
-
---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
-
Thank you very much all of you guys...
Really appreciate it...
Patrice B.
-
Sastraxi: Although it's improper, you can omit the CInt() and it will still work.
-
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?
-
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.
-
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?
-
Kedaman, if you do not include DoEvents, the program can freeze.
-
It won't freeze your program, it's the event's that don't get fired.
Search for Settimer, Sashko
-
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
-
A batch file doesn't wait for a Windows EXE to stop executing before going on to the next command.
-
Even I try to make this executable something like "modal"?
-
It doesn't matter. A DOS batch file and a Win32 app is running on different Virtual Machines.
-
Even Systemmodal won't stop any app to run, but will prevent windows to recieve messages.
-
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...