Opening a custom html page as a dialog

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
haplo567
Newbie
Posts: 2
Joined: Tue Jun 13, 2006 5:30 pm

Opening a custom html page as a dialog

Post by haplo567 » Tue Jun 13, 2006 7:25 pm

I'm trying to create a custom dialog for user input. The problem is that I want my dialog to be more complex than a dialog created with a dialog block can be. Specifically, I want buttons on the form that link to subforms and/or affect other controls on the form. I can create the form fine as an html page (and have done similar for other programs in the past) but I can't figure out how to open the dialog from Macro Scheduler 7.4.005.

My plan was to open it using VBScript, but I haven't been able to get it to work. Here's how I would do it using VBScript from a web page:

Code: Select all

strReturnValue = showModalDialog(strURL , strInputValue, strDialogOptions)
To do the same from a .vbs file is more difficult and I would implement it like this:

Code: Select all

'Launch Internet Explorer
Set oIE = WScript.CreateObject("InternetExplorer.Application")

'Window size and position
oIE.Left = intLeft
oIE.Top = intTop
oIE.Height = intHeight
oIE.Width = intWidth

'Disable all of the below
oIE.MenuBar = 0
oIE.ToolBar = 0
oIE.StatusBar = 0
oIE.Resizable = 0

'Load form
oIE.navigate strURL
oIE.Visible = 1

'Wait until Internet Explorer is ready.
Do While (oIE.Busy)
	WScript.Sleep 200
Loop

WScript.Sleep 1000

'Handle case in which IE is closed.
On Error Resume Next

'Wait until the OK button is clicked.
Do                     
	WScript.Sleep 500
Loop While (oIE.Document.Script.getClose() = False)

'IF an error occurs THEN cancel
If Err <> 0 Then
	Call MsgBox("Canceled", vbOKOnly)
	Exit Sub
End If

'Switch off error handling. 
On Error GoTo 0

'Get values from input boxes, repeat for each oObject
strInput = oIE.Document.frmForm.oObject.Value

'Close Internet Explorer
oIE.Quit
Set oIE = Nothing

The problem is that neither of these options work in a Macro Scheduler VB block. The showModalDialog() function isn't available and the WScript object isn't available.


So my quesiton is:

Does anyone have an idea for how I can open a custom dialog created as an html file from Macro Scheduler?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Jun 13, 2006 7:41 pm

showModalDialog is not a native VBScript function. From a quick Google search I understand it is a DHTML method:

http://msdn.microsoft.com/workshop/auth ... dialog.asp

So it has no relevance in VBscript/Macro Scheduler.

Your second example can be used in Macro Scheduler with:

Code: Select all

VBSTART

Sub DoHTMLDialog

'Launch Internet Explorer
Set oIE = CreateObject("InternetExplorer.Application")

'Window size and position
oIE.Left = intLeft
oIE.Top = intTop
oIE.Height = intHeight
oIE.Width = intWidth

'Disable all of the below
oIE.MenuBar = 0
oIE.ToolBar = 0
oIE.StatusBar = 0
oIE.Resizable = 0

'Load form
oIE.navigate strURL
oIE.Visible = 1

'Wait until Internet Explorer is ready.
Do While (oIE.Busy)
   'WScript.Sleep 200
Loop

'WScript.Sleep 1000

'Handle case in which IE is closed.
On Error Resume Next

'Wait until the OK button is clicked.
Do                     
   'WScript.Sleep 500
Loop While (oIE.Document.Script.getClose() = False)

'IF an error occurs THEN cancel
If Err <> 0 Then
   Call MsgBox("Canceled", vbOKOnly)
   Exit Sub
End If

'Switch off error handling.
On Error GoTo 0

'Get values from input boxes, repeat for each oObject
strInput = oIE.Document.frmForm.oObject.Value

'Close Internet Explorer
oIE.Quit
Set oIE = Nothing

End Sub
 
VBEND

VBRun>DoHTMLDialog
Note you have to remove references to WScript which is a VBScript host app and has no relevance to Macro Scheduler. Sleep is a WScript function, not a standard VBScript function so you can't use that either.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Jun 13, 2006 7:59 pm

Maybe I'm missing something here but I have done this and not used VBscript in Macro Scheduler.

The html can be opened with,

EXE>[drive]:path\filename.html

Any values that need to pass from the html to the script can be passed by having the web page write its info to a file and have the script detect the file then read it.

What I have also done is have the html written by the script using parameters generated from outside data. So the HTML dialog is dynamically generated and based on the current data.

Sorry, I don't have an example that I can post.

haplo567 said:

Code: Select all

The problem is that I want my dialog to be more complex than a dialog
created with a dialog block can be. Specifically, I want buttons on the
form that link to subforms and/or affect other controls on the form.
I won't argue about html making fine looking forms, however what you have stated here could be done with a Macro Scheduler dialog as well. And If you took the time with background images could also be made to look quite nice.

Later,
Dick

haplo567
Newbie
Posts: 2
Joined: Tue Jun 13, 2006 5:30 pm

Post by haplo567 » Tue Jun 13, 2006 9:21 pm

mtettmar: Is there another way to work sleep into the function? Without sleep the do loop is liable to pin the CPU. I could possibly loop using macro scheduler and it's sleep function if VB will retain the pointers between function calls (assuming I make the variables global, etc.). It seems like a lot of work that could be avoided if a sleep function was available.


JRL: I thought of the option to write to a file, though I didn't know about the EXE command (I assumed something like it would be available if I went looking). I was hoping to avoid using a temporary file, though, as it doesn't seem all that efficient. That said, if I go with this route, how have you waited for the form to close in the past? Did you check the contents of the file every once in a while, wait for the window to not be open, etc?

And related to your comment about being able to do this in Macro Scheduler: How do I attach code to dialog buttons in Macro Scheduler?


Thanks for all the help.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Jun 13, 2006 10:09 pm

how have you waited for the form to close in the past?
the easiest is WaitWindowClosed> See the help files. Although you could loop to view a particular section of a file waiting for specific info, or wait for the existance of a file.
I was hoping to avoid using a temporary file
For passing information from one window to another other options that I've used are registry settings, ini files or the system clipboard.
How do I attach code to dialog buttons in Macro Scheduler?
I'm not a programmer, I'm not sure I know exactly what you mean by "attaching code to a dialog button". If you can run your code from Macro Scheduler, you can run it at the click of a dialog button. A dialog button could be set up to open another dialog box, open another html, run an executable, close a different window, pretty much whatever you can think of. See dialog under help.

Hope this is helpful,
Dick

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Jun 14, 2006 7:50 am

haplo567 wrote:mtettmar: Is there another way to work sleep into the function? Without sleep the do loop is liable to pin the CPU. I could possibly loop using macro scheduler and it's sleep function if VB will retain the pointers between function calls (assuming I make the variables global, etc.). It seems like a lot of work that could be avoided if a sleep function was available.
No, VBScript doesn't have a sleep function. There is no way to do this in native VBscript.
And related to your comment about being able to do this in Macro Scheduler: How do I attach code to dialog buttons in Macro Scheduler?
Have you looked at the examples? Have a look at the Calculator sample which comes with Macro Scheduler. Every time a button on the dialog is clicked, code is processed. That code in this case performs some calculation, but could do anything, like open another dialog or executable.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts