Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Sleep operation no longer used in VBscript?

Tags:

vbscript

The "Sleep" command as stated in many places over the internet (including here on this forum) DOES NOT WORK. Is it now an obsolete command?

I am writing the VBScript code like this:

sub button1_onclick()
Wscript.Sleep 1000
div1.innerHTML = textbox1.value
end sub

It should wait 1 second and then execute that simple command. This is an utterly simple statement but it does not work. Plain and simple. It comes up with an error every time saying:

Object Required: 'Wscript'

like image 376
Cheesus Toast Avatar asked Oct 27 '12 00:10

Cheesus Toast


1 Answers

Daniel's answer is absolutely correct about context being the key here. Although you don't have the WScript method available, you do have the full browser DOM, including the window.setTimeout method. With VBScript, the semantics of passing code to setTimeout are a little bit different than JavaScript, but it's still possible:

Sub button1_onclick()
    window.setTimeout GetRef("Delayed"), 1000
End Sub

Sub Delayed()
    div1.innerHTML = textbox1.value
End Sub
like image 118
Cheran Shunmugavel Avatar answered Sep 21 '22 14:09

Cheran Shunmugavel