0

I've looked at Use HTML tags in VBScript and How can I call a vbscript function from html?, but I can't see what is wrong with my code. Can someone look it over and let me know why, when I click the OK button, the window doesn't close? I commented some lines out that I've tried and didn't work.

Dim objIE, objShell
Dim strDX

Set objIE = CreateObject("InternetExplorer.Application")
Set objShell = CreateObject("WScript.Shell")

strDX = "AT-0125B"

objIE.Navigate "about:blank"

objIE.Document.Title = "Covered Diagnosis"
objIE.ToolBar = False
objIE.Resizable = False
objIE.StatusBar = False
objIE.Width = 350
objIE.Height = 200
'objIE.Scrollbars="no"

' Center the Window on the screen
With objIE.Document.ParentWindow.Screen
    objIE.Left = (.AvailWidth - objIE.Width ) \ 2
    objIE.Top = (.Availheight - objIE.Height) \ 2
End With

objIE.document.body.innerHTML = "<b>" & strDX & " is a covered diagnosis code.</b><p>&nbsp;</p>" & _
"<center><input type='submit' value='OK' onclick='VBScript:ClickedOk()'></center>" & _
"<input type='hidden' id='OK' name='OK' value='0'>"

objIE.Visible = True
'objShell.AppActivate "Covered Diagnosis"
'MsgBox objIE.Document.All.OK.Value
Function ClickedOk
'If objIE.Document.All.OK.Value = 1 Then
    'objIE.Document.All.OK.Value = 0
    'objShell.AppActivate "Covered Diagnosis"
    'objIE.Quit
    Window.Close()
'End If
End Function
7
  • your code sets the innerhtml, then executes all the code AFTER the innerhtml defition. at that point the button hasn't been clicked yet, so the if test fails, and window.close() never gets called. Commented Jan 2, 2015 at 15:19
  • Ok. I'm designing it after a working script, but there is a lot less code in mine that the original. I tested the OK.Value in the MsgBox and get 0. How would I do it so that it recognizes the button click? Commented Jan 2, 2015 at 15:41
  • your onclick would have to call a vb function that runs your if test, so it can test the "live" value as changed by the form, not the value that exists at the time you're defining the html. Commented Jan 2, 2015 at 15:48
  • Ok, see my updated code. I called a function, then had the function close the window. Now, the popup doesn't show at all. What am I missing? Commented Jan 2, 2015 at 15:59
  • you forgot VBScript:, so you're trying to call an undefined javascript function. Commented Jan 2, 2015 at 16:02

1 Answer 1

2

The ClickedOk() function is not part of the HTML source code of the new window. Your script starts a new Internet Explorer process, but HTML (or script) code in that process cannot use code from another process (in this case the script process):

yourscript.vbs --> ClickedOk()
     |                 ^
     |                 |
     |                 X
     v                 |
iexplore.exe   --> <input onclick='VBScript:ClickedOk()'>

You'd need IPC methods for communicating with other processes, but browsers usually restrict this kind of access due to security considerations.

So, when you click 'OK', it looks for a ClickedOK function and cannot find it. Thus it will not work.

To make it work, try something like this:

objIE.document.body.innerHTML = "<b>" & strDX & " is a covered diagnosis code.</b><p>&nbsp;</p>" & _
"<center><input type='submit' value='OK' onclick='self.close();'></center>" & _
"<input type='hidden' id='OK' name='OK' value='0'>"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.