Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

internet explorer.application button click check 1

Status
Not open for further replies.

bn2hunt

MIS
May 15, 2003
203
US
I am trying to create a subroutine that when called will have a countdown timer and an OK button. I have the script created using the internetexplorer.application method but when I try to put the code into a subroutine my check for the OK button to be clicked no longer works. Does anybody know why? or a different way to check for the ok button to be clicked? Here is my code
Code:
passint = 10
	Const READYSTATE_COMPLETE = 4
	Set ie = CreateObject ("InternetExplorer.Application")
		ie.navigate "about:blank"
		ie.toolbar = 0
		ie.MenuBar = 0
		ie.statusbar = 0
		ie.width = 250
		ie.height = 250
		ie.left = 0
		ie.top = 0
	Do While ie.ReadyState <> READYSTATE_COMPLETE
		WScript.Sleep 50
	Loop
	ie.visible = True
	
	Dim text
	Set text = ie.document.createElement("textarea")
	loopcnt = passint - 1
	text.Value = passint
	ie.document.body.AppendChild text
	
	Dim okButton
	Set okButton = ie.document.createElement("input")
		okButton.type = "button"
		okButton.value = "OK"
	ie.document.body.AppendChild okButton
	
	Dim Finished: Finished = False
	Set okButton.onclick = GetRef("OK_Clicked")
	
	For I = 0 To loopcnt
		WScript.sleep 1000
		passint = passint - 1
		text.Value = passint
		If finished = True Then i = loopcnt
	Next
	finished = True
	
	Do While Not Finished
		WScript.Sleep 50
	Loop
	WScript.Echo text.value
	ie.Quit

Sub OK_Clicked()
	Finished = True
End Sub

Thanks

Dan
 
>...but when I try to put the code into a subroutine my check for the OK button to be clicked no longer works.

[1] I suppose you have not put the ok_click() inside the sub as well. Most probably you have not otherwise it would be a different question.

[2] To make it work, you have to make Finish global.
[tt]
'move this declaration outside the sub in question.
Dim Finished

sub doCountdown 'your sub in question
'etc etc
[red]'[/red]Dim Finished
Finished = False [blue]'But Keep this to initialize[/blue]
'etc etc
end sub

Sub OK_Clicked()
Finished = True
End Sub
[/tt]
(There are quite a few things you can improve, but I won't bother to change what you desire to make it look like.)
 
Here is the finished subrouting. Thanks for your help tsuji.

Code:
Dim text,okButton,Finished

Timer 10,"This is the text for the timer box"
MsgBox "done"

Sub Timer(sec,boxtext)
' Sets up the IE window
	Const READYSTATE_COMPLETE = 4
	Set ie = CreateObject ("InternetExplorer.Application")
		ie.navigate "about:blank"
		ie.toolbar = 0
		ie.MenuBar = 0
		ie.statusbar = 0
		ie.width = 250
		ie.height = 250
		ie.left = 0
		ie.top = 0
	Do While ie.ReadyState <> READYSTATE_COMPLETE
		WScript.Sleep 50
	Loop
	ie.visible = True
'Displays the text in the IE window
	Set ieDoc = ie.Document
	iedoc.writeln (boxtext & "<br><br>")
'Creates the area for the countdown timer to be displayed
	Set text = ie.document.createElement("textarea")
	loopcnt = sec - 1
	text.Value = sec
'Displays the timer in the textarea
	ie.document.body.AppendChild text
'Creates the OK button
	Set okButton = ie.document.createElement("input")
		okButton.type = "button"
		okButton.value = "OK"
	ie.document.body.AppendChild okButton
	Finished = False
	Set okButton.onclick = GetRef("OK_Clicked")
' Start the loop for the countdown
	For I = 0 To loopcnt
		WScript.sleep 1000
		sec = sec - 1
		text.Value = sec
		If finished = True Then i = loopcnt
	Next
	finished = True
	
	Do While Not Finished
		WScript.Sleep 50
	Loop
	ie.Quit
End Sub

Sub OK_Clicked()
	Finished = True
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top