ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   On Time code (https://www.excelbanter.com/excel-programming/323321-time-code.html)

Kevin

On Time code
 
Is there anyway of using the OnTime command which when reached will exit the
program unless a specific number is inserted into a input box.

Can you advise f the code?

Many thanks.

Kevin.

Bob Phillips[_6_]

On Time code
 
Don't know where OnTime comes into it, but the test can be

ans = Inputbox("Inut number")
If ans < 23 Then End

--

HTH

RP
(remove nothere from the email address if mailing direct)


"kevin" wrote in message
...
Is there anyway of using the OnTime command which when reached will exit

the
program unless a specific number is inserted into a input box.

Can you advise f the code?

Many thanks.

Kevin.




Robin Hammond[_2_]

On Time code
 
Kevin,

If you are using a standard input box I don't think so. You can create a
custom form and show it as a modeless form in XL2000 or higher, then have an
OnTime command check whether the value has been entered by a certain time.
OnTime is not that reliable however and this could easily mess up. So, I've
illustrated a better technique using a timer control:

'Put this in a general Module
'first technique using OnTime, which is easily messed up
'by clicking in the formula bar
'create a userform called frmPassword and add a text box called txtInput

Option Explicit
Option Private Module

Public dtTimeOut As Date 'used by second technique

Sub UnReliableTestForPassword()
frmPassword.Show vbModeless
Application.OnTime Now + TimeSerial(0, 0, 20), "CheckPassword"
End Sub

Sub CheckPassword()
Dim strCheck As String
strCheck = frmPassword.txtInput.Text
Unload frmPassword
If strCheck < "abc" Then
MsgBox "You password was not entered correctly", vbOKOnly, "Timed Out"
End
Else
MsgBox "System access granted", vbOKOnly, "Validation confirmed"
'run other macro to launch system here
End If
End Sub

'second technique using my VBA Timer control which is less easily
circumvented
'add the timer control from
'http://www.enhanceddatasystems.com/ED/Pages/ExcelTimer.htm
'to frmPassword

Sub MoreReliableTestForPassword()
dtTimeOut = Now + TimeSerial(0, 0, 20)
frmPassword.Show vbModeless
With frmPassword.Timer1
.Interval = 1000
.Enabled = True
End With
End Sub

'and put this in frmPassword's code section
Private Sub Timer1_Timer()
Dim strCheck As String
If Now dtTimeOut Then
Timer1.Enabled = False
strCheck = frmPassword.txtInput.Text
If strCheck < "abc" Then
MsgBox "You password was not entered correctly", vbOKOnly, "Timed
Out"
End
Else
MsgBox "System access granted", vbOKOnly, "Validation confirmed"
'run other macro to launch system here
End If
Unload Me
End If
End Sub

Robin Hammond
www.enhanceddatasystems.com

"kevin" wrote in message
...
Is there anyway of using the OnTime command which when reached will exit
the
program unless a specific number is inserted into a input box.

Can you advise f the code?

Many thanks.

Kevin.




Kevin

On Time code
 
Robin,

Many thanks. This works. I was just wondering if there is something similar
for dates. e.g if you want it to time out after say 5 days?

Kind Regards

"kevin" wrote:

Is there anyway of using the OnTime command which when reached will exit the
program unless a specific number is inserted into a input box.

Can you advise f the code?

Many thanks.

Kevin.


Robin Hammond[_2_]

On Time code
 
Kevin,

Glad it works. I seriously doubt it would be reliable to try it for long
periods.

Robin Hammond
www.enhanceddatasystems.com

"kevin" wrote in message
...
Robin,

Many thanks. This works. I was just wondering if there is something
similar
for dates. e.g if you want it to time out after say 5 days?

Kind Regards

"kevin" wrote:

Is there anyway of using the OnTime command which when reached will exit
the
program unless a specific number is inserted into a input box.

Can you advise f the code?

Many thanks.

Kevin.





All times are GMT +1. The time now is 04:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com