|
-
Aug 11th, 2000, 10:43 AM
#1
Thread Starter
Lively Member
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
-
Aug 11th, 2000, 10:55 AM
#2
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
-
Aug 11th, 2000, 10:57 AM
#3
Thread Starter
Lively Member
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
-
Aug 11th, 2000, 10:57 AM
#4
Good Ol' Platypus
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)
-
Aug 11th, 2000, 11:00 AM
#5
Good Ol' Platypus
---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)
-
Aug 11th, 2000, 12:30 PM
#6
Thread Starter
Lively Member
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
-
Aug 11th, 2000, 12:39 PM
#7
Sastraxi: Although it's improper, you can omit the CInt() and it will still work.
-
Aug 11th, 2000, 02:16 PM
#8
New Member
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
-
Aug 11th, 2000, 02:30 PM
#9
transcendental analytic
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.
-
Aug 11th, 2000, 02:44 PM
#10
New Member
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
-
Aug 11th, 2000, 03:09 PM
#11
Kedaman, if you do not include DoEvents, the program can freeze.
-
Aug 11th, 2000, 03:21 PM
#12
transcendental analytic
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.
-
Aug 14th, 2000, 09:30 AM
#13
Thread Starter
Lively Member
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
-
Aug 14th, 2000, 10:30 AM
#14
A batch file doesn't wait for a Windows EXE to stop executing before going on to the next command.
-
Aug 14th, 2000, 11:41 AM
#15
Thread Starter
Lively Member
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
-
Aug 15th, 2000, 06:47 AM
#16
It doesn't matter. A DOS batch file and a Win32 app is running on different Virtual Machines.
-
Aug 15th, 2000, 07:12 AM
#17
transcendental analytic
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.
-
Aug 15th, 2000, 07:17 AM
#18
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|