Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for iebuttons.vbs

(view source code of iebuttons.vbs as plain text)

  1. ' Creates a menu of buttons in IE
  2. ' you click a button and it returns a value
  3. ' Returns 0 if user clicks Cancel of the red X (or alt-F4) to close IE window instead of making a selection 
  4.  
  5. Option Explicit
  6.  
  7. WScript.Echo IEButtons( )
  8.  
  9.  
  10.  
  11. Function IEButtons( )
  12. 	' This function uses Internet Explorer to create a dialog.
  13. 	Dim objIE, sTitle, iErrorNum
  14.  
  15. 	' Create an IE object
  16. 	Set objIE = CreateObject( "InternetExplorer.Application" )
  17. 	' specify some of the IE window's settings
  18. 	objIE.Navigate "about:blank"
  19. 	sTitle="Make your choice " & String( 80, "." ) 'Note: the String( 80,".") is to push "Internet Explorer" string off the window
  20. 	objIE.Document.title = sTitle
  21. 	objIE.MenuBar        = False
  22. 	objIE.ToolBar        = False
  23. 	objIE.AddressBar     = false
  24. 	objIE.Resizable      = False
  25. 	objIE.StatusBar      = False
  26. 	objIE.Width          = 250
  27. 	objIE.Height         = 280
  28. 	' Center the dialog window on the screen
  29. 	With objIE.Document.parentWindow.screen
  30. 		objIE.Left = (.availWidth  - objIE.Width ) \ 2
  31. 		objIE.Top  = (.availheight - objIE.Height) \ 2
  32. 	End With
  33. 	' Wait till IE is ready
  34. 	Do While objIE.Busy
  35. 		WScript.Sleep 200
  36. 	Loop
  37.  
  38.  
  39. 	' Insert the HTML code to prompt for user input
  40. 	objIE.Document.body.innerHTML = "<div align=""center"">" & vbcrlf _
  41. 	                              & "<p><input type=""hidden"" id=""OK"" name=""OK"" value=""0"">" _
  42. 	                              & "<input type=""submit"" value=""  Limited User   "" onClick=""VBScript:OK.value=1""></p>" _
  43. 	                              & "<input type=""submit"" value=""  Standard User "" onClick=""VBScript:OK.value=2""></p>" _
  44. 	                              & "<input type=""submit"" value=""   Power User   "" onClick=""VBScript:OK.value=4""></p>" _
  45. 	                              & "<input type=""submit"" value=""   Admin User   "" onClick=""VBScript:OK.value=8""></p>" _
  46. 	                              & "<p><input type=""hidden"" id=""Cancel"" name=""Cancel"" value=""0"">" _
  47. 	                              & "<input type=""submit"" id=""CancelButton"" value=""       Cancel       "" onClick=""VBScript:Cancel.value=-1""></p></div>"
  48.  
  49. 	' Hide the scrollbars
  50. 	objIE.Document.body.style.overflow = "auto"
  51. 	' Make the window visible
  52. 	objIE.Visible = True
  53. 	' Set focus on Cancel button
  54. 	objIE.Document.all.CancelButton.focus
  55.  
  56.  
  57. 	'CAVEAT: If user click red X to close IE window instead of click cancel, an error will occur.
  58. 	'        Error trapping Is Not doable For some reason
  59. 	On Error Resume Next
  60. 	Do While objIE.Document.all.OK.value = 0 and objIE.Document.all.Cancel.value = 0
  61. 		WScript.Sleep 200
  62. 		iErrorNum = Err.Number
  63. 		If iErrorNum <> 0 Then	'user clicked red X (or alt-F4) to close IE window
  64. 			IEButtons = 0
  65. 			objIE.Quit
  66. 			Set objIE = Nothing
  67. 			Exit Function
  68. 		End if
  69. 	Loop
  70. 	On Error Goto 0
  71.  
  72. 	objIE.Visible = False
  73.  
  74. 	' Read the user input from the dialog window
  75. 	IEButtons = objIE.Document.all.OK.value
  76. 	' Close and release the object
  77. 	objIE.Quit
  78. 	Set objIE = Nothing
  79. End Function
  80.  

page last modified: 2024-04-16; loaded in 0.0197 seconds