|
-
Aug 18th, 2006, 11:02 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Creating a Delay of 60 min
Hi
I am trying to create a function that will delay calling an EXE file for 60 minutes. Example:
The user will get a dialogue window that will prompt him to make a choice, if chooses the install he will click on botton that will delay exeuting the EXE for specific number if min. and after 5 delay another EXE will start automaticaly.
any suggestions will be appriciated. Iam using VB 6.
Thanks
Georges
-
Aug 18th, 2006, 11:09 AM
#2
Re: Creating a Delay of 60 min
One way is to use timer and increment some counter within the timer:
VB Code:
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 100 'fire timer
Timer1.Enabled = True
Timer1.Interval = 60000 '1 minute
End Sub
Private Sub Timer1_Timer()
Static iCounter As Integer
If iCounter = 60 Then
'do something
iCounter = 0
End If
iCounter = iCounter + 1
End Sub
-
Aug 18th, 2006, 11:23 AM
#3
Thread Starter
Hyperactive Member
Re: Creating a Delay of 60 min
Thank,, Why am I getting Error in "Private Sub Form_Load()" in Yellow, and it have TIMER1 in blue? The error Compile error Varialble not defined?
thanks
-
Aug 18th, 2006, 11:24 AM
#4
Re: Creating a Delay of 60 min
Do you have a Timer control on your form?
-
Aug 18th, 2006, 11:26 AM
#5
Thread Starter
Hyperactive Member
Re: Creating a Delay of 60 min
I am sorry, I am new VB I don't know much about it, what do you mean by Timer Control?
thanks
-
Aug 18th, 2006, 11:29 AM
#6
Re: Creating a Delay of 60 min
 Originally Posted by wajdi
I am sorry, I am new VB I don't know much about it, what do you mean by Timer Control?
thanks
On your VB toolbar you will see a control that looks like a stopwatch. That is the Timer control.
You need to place one of those on your form (it is invisible at run time so it doesn't matter where), and put RhinoBull's timer code in its Timer event.
-
Aug 18th, 2006, 11:30 AM
#7
Re: Creating a Delay of 60 min
Look in your IDE's Toolbox which is usually on the left of your screen. Do you see something that looks like a stopwatch? If so then double-click it and it will appear on your form.
-
Aug 18th, 2006, 11:35 AM
#8
Re: Creating a Delay of 60 min
This is another method (probobally (maybe) more accurate) . Just add a timer on your form:
VB Code:
Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Public tmpTime As String
Public endTime As String
Private Sub Form_Load()
Dim startTime As String
Dim minutesToDelay As String
With Timer1
.Interval = 1
.Enabled = True
End With
startTime = CStr(timeGetTime)
minutesToDelay = "60" 'must be a number character, otherwise Val returns 0
endTime = Val(startTime) + Val(minutesToDelay * 60000)
End Sub
Private Sub Timer1_Timer()
tmpTime = Val(timeGetTime)
If tmpTime = endTime Then Shell "Notepad.exe", vbNormalFocus
End Sub
-
Aug 18th, 2006, 11:37 AM
#9
Thread Starter
Hyperactive Member
Re: Creating a Delay of 60 min
Perfect now I am not getting anymore errors, one more qtion, how can I set it in a way after the user tries three time delaying 60 min, it till trigger a specific EXE file?
Thanks
-
Aug 18th, 2006, 11:40 AM
#10
Re: Creating a Delay of 60 min
 Originally Posted by wajdi
Perfect now I am not getting anymore errors, one more qtion, how can I set it in a way after the user tries three time delaying 60 min, it till trigger a specific EXE file?
Thanks
Set up a counter that increments by 1 each time it goes through a 60 minute delay. Each time the delay starts, check the counter. If it equals 3 then trigger the .Exe....
You are talking about a potential 3 hour delay. What if, during that time, I decide to shut my machine off and go home? What happens to your program then?
-
Aug 18th, 2006, 11:42 AM
#11
Re: Creating a Delay of 60 min
Add another String. That string can be used in combination with the Shell command:
VB Code:
Dim delayCount As Integer
Dim myApp As String
myApp = "C:\myApp.exe"
'then in Timer1, when delay reaches 3
If tmpTime = endTime And delayCount = 3 Then Shell myApp, vbNormalFocus
-
Aug 18th, 2006, 11:44 AM
#12
Re: Creating a Delay of 60 min
I would like to see you try this (i mean, it's accurance)
-
Aug 18th, 2006, 11:44 AM
#13
Thread Starter
Hyperactive Member
Re: Creating a Delay of 60 min
It should kill the program, the whole idea of what I am trying to do it force a reboot after few delays, After the user installs the upgrade that we push on their desktops, I want the user to have the choice to delay the reboot three times, each time is a wait of 60min, after the 60 min pass the same window will come up and give the user to reboot or Delay Reboot 60 min, after three delay his computer will reboot. So if he reboot his machine somewhere in the middle of the delays, I am Happy . I program should exit
-
Aug 18th, 2006, 11:54 AM
#14
Thread Starter
Hyperactive Member
Re: Creating a Delay of 60 min
This myApp = "c:\Windows\system32\notepad.exe" keeps giving me errors it does matter what path i enter there.
-
Aug 18th, 2006, 11:55 AM
#15
Re: Creating a Delay of 60 min
 Originally Posted by wajdi
This myApp = "c:\Windows\system32\notepad.exe" keeps giving me errors it does matter what path i enter there.
What is the error?
-
Aug 18th, 2006, 11:57 AM
#16
Thread Starter
Hyperactive Member
Re: Creating a Delay of 60 min
Invalid outside procedure
-
Aug 18th, 2006, 12:03 PM
#17
Re: Creating a Delay of 60 min
-
Aug 18th, 2006, 12:04 PM
#18
Re: Creating a Delay of 60 min
That line of code needs to be inside some Sub or Function. Please post or attach all your code.
-
Aug 18th, 2006, 12:12 PM
#19
Re: Creating a Delay of 60 min
Marty is right. Invalid Outside Procedure is every procedure that is in "Declarations" and is not a declaration.
-
Aug 18th, 2006, 12:14 PM
#20
Thread Starter
Hyperactive Member
Re: Creating a Delay of 60 min
Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Public tmpTime As String
Public endTime As String
Private Sub Form_Load()
Dim startTime As String
Dim minutesToDelay As String
With Timer1
.Interval = 1
.Enabled = True
End With
startTime = CStr(timeGetTime)
minutesToDelay = "60" 'must be a number character, otherwise Val returns 0
endTime = Val(startTime) + Val(minutesToDelay * 60000)
Dim delayCount As Integer
Dim myApp As String
myApp = "C:\windows\system32\notepad.exe"
'then in Timer1, when delay reaches 3
If tmpTime = endTime And delayCount = 3 Then Shell myApp, vbNormalFocus
End Sub
Private Sub Timer1_Timer()
tmpTime = Val(timeGetTime)
If tmpTime = endTime Then Shell "Notepad.exe", vbNormalFocus
End Sub
-
Aug 18th, 2006, 12:21 PM
#21
Re: Creating a Delay of 60 min
VB Code:
myApp = "C:\windows\system32\notepad.exe"
... has to be in a procedure. In your case, it can be only in Form_Load.
-
Aug 18th, 2006, 12:24 PM
#22
Re: Creating a Delay of 60 min
VB Code:
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 100 'fire timer
Timer1.Enabled = True
Timer1.Interval = 60000 '1 minute
End Sub
Private Sub Timer1_Timer()
Static iCounter As Integer
If iCounter = 60 Then
Shell "Notepad.exe", vbNormalFocus
iCounter = 0
End If
iCounter = iCounter + 1
End Sub
You can make your code easier to read if you surround the code with VBCode tags as in this example.
[vbcode]
'Your code
[/vbcode]
which will cause it to show up like this.
-
Aug 18th, 2006, 12:26 PM
#23
Thread Starter
Hyperactive Member
Re: Creating a Delay of 60 min
VB Code:
Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Public tmpTime As String
Public endTime As String
Private Sub Command1_Click()
Dim startTime As String
Dim minutesToDelay As String
With Timer1
.Interval = 1
.Enabled = True
End With
startTime = CStr(timeGetTime)
minutesToDelay = "60" 'must be a number character, otherwise Val returns 0
endTime = Val(startTime) + Val(minutesToDelay * 60000)
Dim delayCount As Integer
Dim myApp As String
myApp = "C:\windows\system32\shutdown.exe"
'then in Timer1, when delay reaches 3
If tmpTime = endTime And delayCount = 3 Then Shell myApp, vbNormalFocus
End Sub
Private Sub Command2_Click()
Shell "c:\windows\system32\shutdown.exe"
End Sub
Private Sub Timer1_Timer()
tmpTime = Val(timeGetTime)
If tmpTime = endTime Then Shell "Notepad.exe", vbNormalFocus
End Sub
-
Aug 18th, 2006, 12:33 PM
#24
Re: Creating a Delay of 60 min
VB Code:
Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Public tmpTime As String
Public endTime As String
[B] Public myApp As String[/B]
[B] Public delayCount As Integer[/B]
Private Sub Command1_Click()
Dim startTime As String
Dim minutesToDelay As String
With Timer1
.Interval = 1
.Enabled = True
End With
[B]myApp = "C:\windows\system32\shutdown.exe"[/B]
startTime = CStr(timeGetTime)
minutesToDelay = "60" 'must be a number character, otherwise Val returns 0
endTime = Val(startTime) + Val(minutesToDelay * 60000)
End Sub
Private Sub Command2_Click()
[B] Shell "c:\windows\system32\shutdown.exe"[/B] '???
End Sub
Private Sub Timer1_Timer()
tmpTime = Val(timeGetTime)
If tmpTime = endTime Then Shell "Notepad.exe", vbNormalFocus
[B]If tmpTime = endTime And delayCount = 3 Then Shell myApp, vbNormalFocus[/B]
End Sub
This should do it. You were declaring "myApp" in Form_Load and reffering to it in Command2_Click. If you want to reffer to some variable in general (more procedures) it must be declared in "Declaration", that's ouside of all procedures. BTW... that won't work. You're not increasing the delayCount. When every hour goes by, increase it for 1. Otherwise, this won't work.
-
Aug 18th, 2006, 12:33 PM
#25
Re: Creating a Delay of 60 min
wajdi, please see my post #22.
-
Aug 18th, 2006, 01:08 PM
#26
Thread Starter
Hyperactive Member
Re: Creating a Delay of 60 min
Hi Guys
Thats what I have before as a VB script that works with two functions:
first bottun: REBOOT NOW
second bottun: REboot in 60min
and here is the script:
VB Code:
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Sub Form_Activate()
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Private Sub Command1_Click()
Shell "shutdown.exe -r"
End Sub
Private Sub Command2_Click()
Shell "shutdown.exe -r -t 3600"
End Sub
Now if I want to add our delay functions to the existing existing script, is that how its supposed to look?
VB Code:
Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Public tmpTime As String
Public endTime As String
Public myApp As String
Public delayCount As Integer
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Sub Form_Activate()
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Private Sub Command1_Click()
Shell "shutdown.exe -r"
End Sub
Private Sub Command2_Click()
Shell "shutdown.exe -r -t 3600"
End Sub
Private Sub Command1_Click()
Dim startTime As String
Dim minutesToDelay As String
With Timer1
.Interval = 1
.Enabled = True
End With
myApp = "C:\windows\system32\shutdown.exe"
startTime = CStr(timeGetTime)
minutesToDelay = "60" 'must be a number character, otherwise Val returns 0
endTime = Val(startTime) + Val(minutesToDelay * 60000)
End Sub
Private Sub Timer1_Timer()
tmpTime = Val(timeGetTime)
If tmpTime = endTime Then Shell "Notepad.exe", vbNormalFocus
If tmpTime = endTime And delayCount = 3 Then Shell myApp, vbNormalFocus
End Sub
-
Aug 18th, 2006, 01:10 PM
#27
Thread Starter
Hyperactive Member
Re: Creating a Delay of 60 min
sorry guys, found a mistake, but that would be the final version.
VB Code:
Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Public tmpTime As String
Public endTime As String
Public myApp As String
Public delayCount As Integer
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Sub Form_Activate()
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Private Sub Command2_Click()
Shell "shutdown.exe -r -t 3600"
End Sub
Private Sub Command1_Click()
Dim startTime As String
Dim minutesToDelay As String
With Timer1
.Interval = 1
.Enabled = True
End With
myApp = "C:\windows\system32\shutdown.exe"
startTime = CStr(timeGetTime)
minutesToDelay = "60" 'must be a number character, otherwise Val returns 0
endTime = Val(startTime) + Val(minutesToDelay * 60000)
End Sub
Private Sub Timer1_Timer()
tmpTime = Val(timeGetTime)
If tmpTime = endTime Then Shell "Notepad.exe", vbNormalFocus
If tmpTime = endTime And delayCount = 3 Then Shell myApp, vbNormalFocus
End Sub
-
Aug 18th, 2006, 01:16 PM
#28
Re: Creating a Delay of 60 min
What are you trying to do, wajdi ??? You asked about delays and you got two samples so I'm a little confused as to what else would you need?
If your original question has been answered then set this thread as resolved and perhaps open new one if you have some other (unrelated to current) questions.
Thanks.
-
Aug 18th, 2006, 01:21 PM
#29
Thread Starter
Hyperactive Member
Re: Creating a Delay of 60 min
Ok I will open a new thread, thanks for everyone and their input.
-
Aug 18th, 2006, 03:49 PM
#30
Re: Creating a Delay of 60 min
Good, but before you do that do us a favour and go to Thread Tools (menu) and click on the "Mark Thread Resolved" option.
Thanks.
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
|