Consulting

Results 1 to 18 of 18

Thread: Inputbox & Time

  1. #1

    Inputbox & Time

    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 
    
    
    Formatting tags added by mark007
    thnaks for all the help

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    24,828
    Location
    You could use a custom form with an Ontime macro that will unload it.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    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 
    
    
    Formatting tags added by mark007

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    24,828
    Location
    That method is notoriously unreliable. Too often it fails to timeout.

    Not recommended.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Suppose that would depend upon the consequences of it failing to time out weighed againgst the percentage frequency of it not timing out.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    24,828
    Location
    Absolutely not. The possibility of even one failure out in the field makes it unusable to me.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    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.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    24,828
    Location
    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?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    And that was the first point I made.

  10. #10
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,748
    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 
    
    
    Formatting tags added by mark007

  11. #11
    Quote Originally Posted by mikerickson View Post
    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 
    
    
    Formatting tags added by mark007
    Hi, i have same problem, I need Temporized Inputbox, please look:

    http://www.vbaexpress.com/forum/show...066#post360066

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

    thanks

  12. #12

  13. #13
    Quote Originally Posted by Logit View Post
    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/show...user-not-input


    attached sample file

    excel-InputBox-Mike.zip


    excel-Inputbox1 - error.jpg

  14. #14
    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

  15. #15
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,748
    Quote Originally Posted by xman2000 View Post
    ...

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

    thanks
    That 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.

  16. #16
    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.
    Last edited by xman2000; 04-21-2017 at 02:44 PM.

  17. #17
    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 :
    Attached Files Attached Files
      To view attachments your post count must be 0 or greater. Your post count is 0 momentarily.

  18. #18
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •