Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
daniel chen
 
Posts: n/a
Default Time-out for InputBox

Sub InputBoxTimeout()
' How do I add a time-out conponent to this? Someone please
Range("A1") = InputBox(prompt:=" Enter a number within 1 minute," & vbLf & "
otherwise, 4 will be assumed.")
End Sub


  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Best way is to have a little userform that you load with a textbox for
input. In the userfor activate, add this code

Application.Ontime Now + TimeSerial(0,1,0),"KillForm"

and then have a sub in a standard code mode

Public Sub KillForm()
Unload Userform1
End SUb

--

HTH

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


"daniel chen" wrote in message
...
Sub InputBoxTimeout()
' How do I add a time-out conponent to this? Someone please
Range("A1") = InputBox(prompt:=" Enter a number within 1 minute," & vbLf &

"
otherwise, 4 will be assumed.")
End Sub




  #3   Report Post  
daniel chen
 
Posts: n/a
Default

Hi Bob
My macro should look more like this.
Sub InputBoxTimeout()
Dim ans As Variant
ans = ""
' How do I add a time-out conponent to this? Someone please
ans = InputBox(prompt:=" Enter a number within 1 minute," & vbLf & _
" otherwise, 4 will be assumed.")
If ans = "" Then Range("A1") = 4
If ans < "" Then Range("A1") = ans
End Sub

I have never used a Userform. Please give me some hint where to start.
Thanks

"Bob Phillips" wrote in message
...
Best way is to have a little userform that you load with a textbox for
input. In the userfor activate, add this code

Application.Ontime Now + TimeSerial(0,1,0),"KillForm"

and then have a sub in a standard code mode

Public Sub KillForm()
Unload Userform1
End SUb

--

HTH

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


"daniel chen" wrote in message
...
Sub InputBoxTimeout()
' How do I add a time-out conponent to this? Someone please
Range("A1") = InputBox(prompt:=" Enter a number within 1 minute," & vbLf
&

"
otherwise, 4 will be assumed.")
End Sub






  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

First, take a look at Debra Dalgleish's site:
http://www.contextures.com/xlUserForm01.html

Just to get familiar with working with userforms.

The when you're done, try creating a userform (named userform1) that contains a
textbox (to get the input), a label (just for error messages) and two buttons
(cancel and ok).

Then in a general module, put this:

Option Explicit
Public RunWhen As Double
Public myVal As Variant
Public myDefaultValue As Long
Dim UF1 As UserForm1
Sub testme()
Set UF1 = New UserForm1
UF1.Show

Select Case LCase(myVal)
Case Is = "timedout"
myVal = myDefaultValue 'some default
Case Is = "cancel"
myVal = 0 'what to do if user cancelled
'exit sub '????
Case Else
myVal = CLng(myVal)
End Select

MsgBox myVal
End Sub
Sub KillForm()
myVal = "TimedOut"
Call KillTimer
Unload UF1
End Sub
Sub KillTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, _
procedu="killForm", schedule:=False
On Error GoTo 0
End Sub

Then behind the userform, put this code:

Option Explicit
Dim blkProc As Boolean
Private Sub CommandButton1_Click()
myVal = "Cancel"
Call KillTimer
Unload Me
End Sub
Private Sub CommandButton2_Click()
Call KillTimer
If IsNumeric(Me.TextBox1.Value) Then
myVal = Me.TextBox1.Value
Unload Me
Else
Me.Label1.Caption = "Please enter a number"
End If
End Sub
Private Sub TextBox1_Change()
If blkProc = True Then
Exit Sub
Else
Call KillTimer
End If
End Sub
Private Sub UserForm_Initialize()
RunWhen = Now + TimeSerial(0, 1, 0) 'hr,min,sec
Application.OnTime RunWhen, "KillForm"
Me.Label1.Caption = ""

myDefaultValue = 4 'or whatever you want

blkProc = True
Me.TextBox1.Value = myDefaultValue
blkProc = False
End Sub

You'll get 3 different types of answers from the userform--Cancel (if the user
hit the cancel button), TimedOut (if the form times out) or a number.

I wasn't sure what to do if the user cancels.

You can read more about the scheduling procedures at Chip Pearson's site:
http://www.cpearson.com/excel/ontime.htm

=======
For testing purposes, you may want to use something smaller than a minute.

And this procedure kills the timer if the user clicks on a button or starts
typing in the textbox.


daniel chen wrote:

Hi Bob
My macro should look more like this.
Sub InputBoxTimeout()
Dim ans As Variant
ans = ""
' How do I add a time-out conponent to this? Someone please
ans = InputBox(prompt:=" Enter a number within 1 minute," & vbLf & _
" otherwise, 4 will be assumed.")
If ans = "" Then Range("A1") = 4
If ans < "" Then Range("A1") = ans
End Sub

I have never used a Userform. Please give me some hint where to start.
Thanks

"Bob Phillips" wrote in message
...
Best way is to have a little userform that you load with a textbox for
input. In the userfor activate, add this code

Application.Ontime Now + TimeSerial(0,1,0),"KillForm"

and then have a sub in a standard code mode

Public Sub KillForm()
Unload Userform1
End SUb

--

HTH

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


"daniel chen" wrote in message
...
Sub InputBoxTimeout()
' How do I add a time-out conponent to this? Someone please
Range("A1") = InputBox(prompt:=" Enter a number within 1 minute," & vbLf
&

"
otherwise, 4 will be assumed.")
End Sub





--

Dave Peterson
  #5   Report Post  
daniel chen
 
Posts: n/a
Default

Hi Dave
I will do that, thanks.

"Dave Peterson" wrote in message
...
First, take a look at Debra Dalgleish's site:
http://www.contextures.com/xlUserForm01.html

Just to get familiar with working with userforms.

The when you're done, try creating a userform (named userform1) that
contains a
textbox (to get the input), a label (just for error messages) and two
buttons
(cancel and ok).

Then in a general module, put this:

Option Explicit
Public RunWhen As Double
Public myVal As Variant
Public myDefaultValue As Long
Dim UF1 As UserForm1
Sub testme()
Set UF1 = New UserForm1
UF1.Show

Select Case LCase(myVal)
Case Is = "timedout"
myVal = myDefaultValue 'some default
Case Is = "cancel"
myVal = 0 'what to do if user cancelled
'exit sub '????
Case Else
myVal = CLng(myVal)
End Select

MsgBox myVal
End Sub
Sub KillForm()
myVal = "TimedOut"
Call KillTimer
Unload UF1
End Sub
Sub KillTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, _
procedu="killForm", schedule:=False
On Error GoTo 0
End Sub

Then behind the userform, put this code:

Option Explicit
Dim blkProc As Boolean
Private Sub CommandButton1_Click()
myVal = "Cancel"
Call KillTimer
Unload Me
End Sub
Private Sub CommandButton2_Click()
Call KillTimer
If IsNumeric(Me.TextBox1.Value) Then
myVal = Me.TextBox1.Value
Unload Me
Else
Me.Label1.Caption = "Please enter a number"
End If
End Sub
Private Sub TextBox1_Change()
If blkProc = True Then
Exit Sub
Else
Call KillTimer
End If
End Sub
Private Sub UserForm_Initialize()
RunWhen = Now + TimeSerial(0, 1, 0) 'hr,min,sec
Application.OnTime RunWhen, "KillForm"
Me.Label1.Caption = ""

myDefaultValue = 4 'or whatever you want

blkProc = True
Me.TextBox1.Value = myDefaultValue
blkProc = False
End Sub

You'll get 3 different types of answers from the userform--Cancel (if the
user
hit the cancel button), TimedOut (if the form times out) or a number.

I wasn't sure what to do if the user cancels.

You can read more about the scheduling procedures at Chip Pearson's site:
http://www.cpearson.com/excel/ontime.htm

=======
For testing purposes, you may want to use something smaller than a minute.

And this procedure kills the timer if the user clicks on a button or
starts
typing in the textbox.


daniel chen wrote:

Hi Bob
My macro should look more like this.
Sub InputBoxTimeout()
Dim ans As Variant
ans = ""
' How do I add a time-out conponent to this? Someone please
ans = InputBox(prompt:=" Enter a number within 1 minute," & vbLf & _
" otherwise, 4 will be assumed.")
If ans = "" Then Range("A1") = 4
If ans < "" Then Range("A1") = ans
End Sub

I have never used a Userform. Please give me some hint where to start.
Thanks

"Bob Phillips" wrote in message
...
Best way is to have a little userform that you load with a textbox for
input. In the userfor activate, add this code

Application.Ontime Now + TimeSerial(0,1,0),"KillForm"

and then have a sub in a standard code mode

Public Sub KillForm()
Unload Userform1
End SUb

--

HTH

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


"daniel chen" wrote in message
...
Sub InputBoxTimeout()
' How do I add a time-out conponent to this? Someone please
Range("A1") = InputBox(prompt:=" Enter a number within 1 minute," &
vbLf
&
"
otherwise, 4 will be assumed.")
End Sub





--

Dave Peterson





  #6   Report Post  
Bob Phillips
 
Posts: n/a
Default

Some reading matter

http://www.microsoft.com/ExcelDev/Articles/sxs11pt1.htm
Lesson 11: Creating a Custom Form
Excerpted from Microsoft® Excel 97 Visual Basic® Step by Step.

http://support.microsoft.com/default.aspx?kbid=161514
XL97: How to Use a UserForm for Entering Data

http://support.microsoft.com/default.aspx?kbid=213749
XL2000: How to Use a UserForm for Entering Data

http://support.microsoft.com/default.aspx?kbid=168067
File Title: Microsoft(R) Visual Basic(R) for Applications Examples for
Controlling UserForms in Microsoft Excel 97

Peter Aiken Articles:
Part I
http://msdn.microsoft.com/library/en...FormsPartI.asp

Part II
http://msdn.microsoft.com/library/en...ormsPartII.asp


--

HTH

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


"daniel chen" wrote in message
...
Hi Bob
My macro should look more like this.
Sub InputBoxTimeout()
Dim ans As Variant
ans = ""
' How do I add a time-out conponent to this? Someone please
ans = InputBox(prompt:=" Enter a number within 1 minute," & vbLf & _
" otherwise, 4 will be assumed.")
If ans = "" Then Range("A1") = 4
If ans < "" Then Range("A1") = ans
End Sub

I have never used a Userform. Please give me some hint where to start.
Thanks

"Bob Phillips" wrote in message
...
Best way is to have a little userform that you load with a textbox for
input. In the userfor activate, add this code

Application.Ontime Now + TimeSerial(0,1,0),"KillForm"

and then have a sub in a standard code mode

Public Sub KillForm()
Unload Userform1
End SUb

--

HTH

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


"daniel chen" wrote in message
...
Sub InputBoxTimeout()
' How do I add a time-out conponent to this? Someone please
Range("A1") = InputBox(prompt:=" Enter a number within 1 minute," &

vbLf
&

"
otherwise, 4 will be assumed.")
End Sub








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding time damezumari Excel Discussion (Misc queries) 2 June 20th 05 08:35 PM
time differences in a column 68magnolia71 Excel Worksheet Functions 3 May 9th 05 09:46 PM
Time Sheet Calculation Help Needed! sax30 Excel Worksheet Functions 2 April 26th 05 08:08 PM
Time Sheets Lady Layla Excel Discussion (Misc queries) 1 March 23rd 05 03:22 PM
unmet challenge boris Excel Worksheet Functions 2 March 16th 05 02:13 PM


All times are GMT +1. The time now is 05:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"