Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   JavaScript and Client-Side Browser Scripting (http://www.programmingforums.org/forum23.html)
-   -   VBScript - Timed Message Box? (http://www.programmingforums.org/showthread.php?t=10537)

randum77 Jun 27th, 2006 10:51 AM

VBScript - Timed Message Box?
 
I am searching around on google and will continue to do so till i figure this out, but figured i'de post here as well.

Is there an easy way to script a MsgBox that is timed. Once the time is over, it will close itself. From what i've found i can do this through VB.net, but I can't find it for Script yet. Any suggestions would be greatly appreciated.

I do know how to do the Msgbox command to get one to come up, but i can only do it with required user interaction. This is what I don't want.

melbolt Jun 27th, 2006 11:09 AM

This is very similar to what you need to do, only instead of opening a msgbox when the time is up, open it at the beginning and close it at the end.

:

'*************************************************************
'This program makes use of a recursive procedure HandleTime.
'The important aspects of the code are "Status" and "setTimeOut".
'Status is an attribute of the Window object in VBScript and is used to
'change the status message of the active window.
'setTimeOut is a VBScript function that tells after how much time the timer
'would stop and accordingly it calls a function passed into it to take some
'action when the time is up.
'This procedure calls its self after every 1 sec (I have taken 1sec = 950ms
' here) and accordingly the variables hr, min and sec are decremented.
'*************************************************************
Sub HandleTime
    if hr=0 and min=0 and sec=0 then
        EndTime
        '**When hr, min and sec are all 0, this means that the time is up
        '**and EndTime procedure is 'called.
    elseif min>=0 and sec>0 then
        sec=sec-1
        status=hr & ":" & min & ":" & sec
        '**Whenever the second changes the Status of the window has to
        'be changed.
        intTimerID=setTimeOut("HandleTime",950, "VBScript")
        '**setTimeOut function returns a unique timer id that is used to
        'keep track of the time.
        '**When the time is up the timer id is destroyed automatically.
    elseif min>0 and sec=0 then
        min=min-1
        sec=59
        status=hr & ":" & min & ":" & sec
        intTimerID=setTimeOut("HandleTime",950, "VBScript")
    elseif hr>=0 and min=0 then
        hr=hr-1
        min=59
        sec=59
        status=hr & ":" & min & ":" & sec
        intTimerID=setTimeOut("HandleTime",950, "VBScript")
    end if
End Sub

Sub EndTime
    clearTimeOut intTimerID
    '**clearTimeOut is a built in procedure of VBScript which is used to
    '**clear and destroy the timer id explicitly
    status = "Your Time Ended"
    '**When the time ends the status bar displays this message.
    msgbox "Time Up"
End Sub


taken from:
http://www.codeproject.com/asp/webtimer.asp

randum77 Jun 27th, 2006 11:13 AM

Melbolt, thank you very much. I'll go ahead and mess with that till I understand it completely, then modify to work the way I need! *thumbs up*

randum77 Jun 27th, 2006 3:09 PM

After reading through the ElseIf and making sense of it all i really like how they use it counts down. My problem is, I want the box to close automatically after 6 seconds without user interaction. More like a, "ok, things are working" and gone. I might be stabbing in the dark at something that doesn't exist. Also, i am probably not experienced enough to know all the internal functions or how to properly search them for the right key words. Once again, thank you for all the help.

randum77 Jun 27th, 2006 3:13 PM

Ok, found a link the directs me to using the PopUp method. This is bassically what it's saying to do.

:

Const wshYes = 6
Const wshNo = 7
Const wshYesNoDialog = 4
Const wshQuestionMark = 32

Set objShell = CreateObject("Wscript.Shell")

intReturn = objShell.Popup("Do you want to delete this file?", _
    10, "Delete File", wshYesNoDialog + wshQuestionMark)

If intReturn = wshYes Then
    Wscript.Echo "You clicked the Yes button."
ElseIf intReturn = wshNo Then
    Wscript.Echo "You clicked the No button."
Else
    Wscript.Echo "The popup timed out."
End If


The rest of the information can be located at Linky!


All times are GMT -5. The time now is 8:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC