PDA

View Full Version : Inputbox & Time



CCkfm2000
10-30-2007, 05:25 AM
Hi all..

Is there a way to bypass the inputbox if the time has elapsed 30 seconds and nothing is entered in the Inputbox?

I'm using the following code.

Dim WeekNo As Integer
Dim WeekNo As Integer
Sub GetWeekno()
WkNo = 44
WeekNo = InputBox("Please Enter Week No. ", "Enter Week No. ", WkNo)
MsgBox WeekNo
End Sub


thnaks for all the help

Bob Phillips
10-30-2007, 06:49 AM
You could use a custom form with an Ontime macro that will unload it.

Badger101
10-30-2007, 07:19 AM
Or maybe you could use a wshshell popup to timeout a message box which only brings up the inputbox if no is clicked but times out otherwise leaving the 44.




Sub GetWeekno()
'Need to set reference to Windows Script Host Object Model
Dim SH As IWshRuntimeLibrary.WshShell
Dim WkNo As Integer
Dim BtnRepsonse
Set SH = New IWshRuntimeLibrary.WshShell
WkNo = 44
BtnResponse = SH.Popup("Stick With Week " & WkNo, 4, "", 4 + 32)
If BtnResponse = 7 Then WkNo = InputBox("Please Enter Week No. ", "Enter Week No. ")
MsgBox WkNo
End Sub

Bob Phillips
10-30-2007, 07:42 AM
That method is notoriously unreliable. Too often it fails to timeout.

Not recommended.

Badger101
10-30-2007, 07:49 AM
Suppose that would depend upon the consequences of it failing to time out weighed againgst the percentage frequency of it not timing out.

Bob Phillips
10-30-2007, 07:52 AM
Absolutely not. The possibility of even one failure out in the field makes it unusable to me.

Badger101
10-30-2007, 08:04 AM
Would have to disagree with that. Like everything in life today its all a simple risk assessment. But would say If the risk can be removed then might as well remove it, depends how you want to tackle the problem. At least the OP has another option.

Bob Phillips
10-30-2007, 08:16 AM
Risk management is all about mitigation. If you know something is likely (will?) happen, you do something about it. What is your proposed course of action for dealing with that when it happens to some poor unsuspecting user? Tell them to go into the task manager and stop the process?

Badger101
10-30-2007, 09:58 AM
And that was the first point I made.

mikerickson
10-30-2007, 03:33 PM
Perhaps something like this. You may have to do some juggling to keep the variable values from main>Skipper>Main.


Sub mainRoutine(Optional skipFirstPart As Boolean)

If skipFirstPart Then GoTo endHalf

Rem some code

Application.OnTime Now + TimeValue("0:0:30"), "Skipper"
UserInput = Application.InputBox("enter something")
Application.OnTime proceedure:="Skipper", schedule:=False

endHalf:
Rem more code
End Sub

Sub Skipper()
Call mainRoutine(True)
End
End Sub

xman2000
04-21-2017, 10:16 AM
Perhaps something like this. You may have to do some juggling to keep the variable values from main>Skipper>Main.


Sub mainRoutine(Optional skipFirstPart As Boolean)

If skipFirstPart Then GoTo endHalf

Rem some code

Application.OnTime Now + TimeValue("0:0:30"), "Skipper"
UserInput = Application.InputBox("enter something")
Application.OnTime proceedure:="Skipper", schedule:=False

endHalf:
Rem more code
End Sub

Sub Skipper()
Call mainRoutine(True)
End
End Sub

Hi, i have same problem, I need Temporized Inputbox, please look:

http://www.vbaexpress.com/forum/showthread.php?59240-inputBox-default-input-in-code-user-not-input&p=360066#post360066

but have a error in this line: proceedure:="Skipper"
error is not in English language.

thanks

Logit
04-21-2017, 10:48 AM
proceedure =procedure

xman2000
04-21-2017, 12:48 PM
proceedure =procedure

Logit,

yes, i fix this mistake, but gives other error "argument is not optional" (free translating of Portuguese) in this line: Application.OnTime

if fix this with put the time after Ontime, and stop the error message.
but i not make this work.

i need return the answer of Inputbox.
i set automatically answer to number value:"4" and i need return this value in a variable long.

Logit, please, help me in my Thread:
http://www.vbaexpress.com/forum/showthread.php?59240-inputBox-default-input-in-code-user-not-input


attached sample file

18990


18989

xman2000
04-21-2017, 01:51 PM
some user provide an working example about this code of Mikerickson above ?? please!
I did not understand why the inputbox does not show or why it does not return value

my goal is Inputbox not show but automatically answer yes and return the default value to a variable.

thanks

mikerickson
04-21-2017, 02:12 PM
...

my goal is Inputbox not show but automatically answer yes and return the default value to a variable.

thanksThat is the problem with adding your question onto an old different question. The OP was about continuing a procedure after a certain amount of time. (which my code does, it also ENDs VBA and erases all variable values).
Your problem is about returning a value after a certain amount of time, which my code will not do, nor do I know how to do that.

xman2000
04-21-2017, 02:26 PM
Hi, mikerickson,

ok, you maybe help me on my thread in link above.
in your code, not shows the Inputbox like the OP speak in first post. I not understand.

i need invoke the INputbox to erase (re-start) only 1one variable of array afther Redim.
i need increases the value of one ForNext Loop (1 to 125) and clean the variable to re-start in 2 (not preserve first 1)
If i only change the value (1 to 2, 2 to 2 , etc ) adn click on commandbutton in worksheet the code runs ok.
but if i use 1 to 125 gives error.

i think if i invoke inputbox and this uptade the code will clean old value of ForNext in the Array and will works.

thanks.

edit: i not understand Inputbox not shows.
edit: Mike, please a sample file with your code like your think, please, i think will help me.

Logit
04-21-2017, 02:55 PM
I've looked at this several times today. Have not been able to determine a solution for you.

If I understand your needs correctly ... after 30 seconds you want the Input Box to go away if an entry was not typed into the field.

Have you considered, rather than using the Input Box, creating your own "Input Box" from a User Form and TextBox / Command Button ?
If the design of the Input Box is something you are determined to have for your project, you can alter the UserForm to look exactly like
it.

See attached :

xman2000
04-21-2017, 03:10 PM
Logit, thanks very, very mutch.
i consider using this userform if I do not find another solution.
I really consider use it
But I still want to try another more practical way that every time I need to create or find a userform.


I am preparing a sample file with my original code.
Maybe I do not prevail on an Inputbox but rather just referesh the code, problem i need refresh the code with new value (increment the value in start the code , like 1 , 2, 3, 4, etc.

i will post my original code in my thread.
please look.