none
I need a timed vbs script! RRS feed

  • Question

  • Hello,

    I am working on a simple vbscript in notepad and I need a few of my boxes to only appear for a few seconds can you help me?

    lets say this is one of my boxes:

     

    msgbox "hello" ,7 , "hi"

     

    how would I make it so that it's only displayed for a couple of seconds.

    also could you explain how you made it work.

    Thank you very much in advance

    luke~

    Tuesday, February 22, 2011 6:33 PM

Answers

  • You can use WshShell.Popup method.
    Uros Calakovic
    Tuesday, February 22, 2011 6:38 PM
    Moderator
  • As the WSH document clearly states , the second argument is

    nSecondsToWait

        Optional. Numeric value indicating the maximum length of time (in seconds) you want the pop-up message box displayed.

    Therefore, change the second argument to match you need, for example ...

    ntReturn = objShell.Popup("Click Yes or No!", 60, "My Title", vbYesNo + vbQuestion)

    will wait for up to 60 seconds.


    Tom Lavedas
    Wednesday, February 23, 2011 8:33 PM
    Moderator

All replies

  • You can use WshShell.Popup method.
    Uros Calakovic
    Tuesday, February 22, 2011 6:38 PM
    Moderator
  • Thank you for replying.

    But where and how would I use WshShell.Popup?? And how would I set the time I want?

     

    Wednesday, February 23, 2011 6:20 PM
  • Find documentation in WSH docs index under Popup:

    WSH 5.6+ documentation download (URL all one line)
    http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en


    Tom Lavedas
    Wednesday, February 23, 2011 6:27 PM
    Moderator
  • OK, well I tried this:

     

    intbutton = object.Popup(hello,5,hello,7)

     

    But I get an error saying

    line: 1

    Char: 1

    error: Object required: 'object'

    code: 800A01A8

    source: Microsoft VBscript runtime error

     

    what did I do wrong?

    Wednesday, February 23, 2011 6:39 PM
  • The object MUST be an instance of the WScript.Shell object, as described in the documentation, therefore you need something like this ...

      set oWShell = createobject("WScript.Shell")
      intbutton = object.Popup(hello,5,hello,7)

    The examples in the documentation seem self evident to me.


    Tom Lavedas
    Wednesday, February 23, 2011 8:04 PM
    Moderator
  • Thank you very much for all of your help but 1 last thing,I got this to work:

     

    Set objShell = CreateObject("Wscript.Shell")

    intReturn = objShell.Popup("Click Yes or No!", 0001, "My Title", vbYesNo + vbQuestion)


    If (intReturn = 1) Then

      Wscript.Echo "Popup timed out"

    End If

    But how do I change the number of seconds it lasts for?

     

    Wednesday, February 23, 2011 8:25 PM
  • As the WSH document clearly states , the second argument is

    nSecondsToWait

        Optional. Numeric value indicating the maximum length of time (in seconds) you want the pop-up message box displayed.

    Therefore, change the second argument to match you need, for example ...

    ntReturn = objShell.Popup("Click Yes or No!", 60, "My Title", vbYesNo + vbQuestion)

    will wait for up to 60 seconds.


    Tom Lavedas
    Wednesday, February 23, 2011 8:33 PM
    Moderator