By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,032 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

Execute VBScript Subroutine from php

ravioliman
P: 6
How do I execute a vbs subroutine from php. I found this on the web and is in my php code:
Expand|Select|Wrap|Line Numbers
  1.   $scripter = new COM("MSScriptControl.ScriptControl");
  2.   $scripter->Language = "vbscript";
  3.   $k = $scripter->eval(UnBusyInvoice());   <<--my subroution
  4.   print "Result: $k\n";
  5.   $scripter = null;  
  6.  
If fails as follows:
Expand|Select|Wrap|Line Numbers
  1. Fatal error: "Call to undefined function UnBusyInvoice() in C:\wamp\www\r1\vchrAdd.php on line 200"
  2.  
The subroutine is in the <head> </head> section as follows:
Expand|Select|Wrap|Line Numbers
  1. <script language="vbscript">
  2.  
  3. Dim myObjSrv
  4. mySrvObj = CreateObject("ImageDisplay.ImageDisplayInterface")
  5.  
  6. Sub UnBusyInvoice()  
  7.    Dim  vDocID, vStatus, iResult
  8.    vDocID = document.getElementByID("docID").value
  9.  
  10.     mySrvObj = CreateObject("ImageDisplay.ImageDisplayInterface")  <<--create automation server
  11.  
  12.    iResult = mySrvObj.UnBusyInvoice(vDocID, vStaus)       <<--execute method on automation server
  13.  
  14.    if vStatus = 0 then           <<-- check return statue
  15.        document.getElementByID("docID").value = ""
  16.    end if
  17. document.getElementByID("status1").value = vStaus
  18.  
  19.  
  20. End sub
  21. </script>
  22.  
Thanks for any help you can give.
Aug 28 '08 #1
Share this Question
Share on Google+
5 Replies


Atli
Expert 5K+
P: 5,058
Hi.

Shouldn't the VBScript code in the eval call be quoted?
The way you are calling it now, PHP will try to execute a PHP function called UnBusyInvoice() and pass the result to the eval call, which fails because there is no such function.
Aug 28 '08 #2

ravioliman
P: 6
Thanks for replying...

When I put quotes around the vbs subroutine
Expand|Select|Wrap|Line Numbers
  1. if ($id == 8) { 
  2.   $scripter = new COM("MSScriptControl.ScriptControl");
  3.   $scripter->Language = "vbscript";
  4.   $k = $scripter->eval("UnBusyInvoice()");
  5.   print "Result: $k\n";
  6.   $scripter = null;
  7. }
  8.  
I got a nasty message:

Fatal error: Uncaught exception 'com_exception' with message
Source: Microsoft VBScript runtime error
Description:Type mismatch: 'UnBusyInvoice'' in C:\wamp\www\resume3\vchrAdd.php:207
Stack trace: #0
C:\wamp\www\resume3\vchrAdd.php(207): com->eval('UnBusyInvoice()') #1 {main} thrown in
C:\wamp\www\resume3\vchrAdd.php on line 207
Aug 29 '08 #3

Atli
Expert 5K+
P: 5,058
Looks like a problem with the VBScript code.
Don't know enough about VBScript to say for sure, but it looks to me like it doesn't recognize the subroutine you are calling.
Aug 29 '08 #4

ravioliman
P: 6
Looks like a problem with the VBScript code.
Don't know enough about VBScript to say for sure, but it looks to me like it doesn't recognize the subroutine you are calling.

Thanks for your reply. I can execute the vbs subroutine all day long using a form element such as a button's onClick or onKeyDown event. Just don't know what to put in the Link area of the menu to execute vbs subroutine?

Thanks much again.
Aug 29 '08 #5

Atli
Expert 5K+
P: 5,058
Ahhhh ok. I see the problem now.

The VBScript subroutine you are trying to execute is sent to the client as a part of the server response, making it available to the client-side scripts (such as the onclick event of a HTML element).
PHP will try to execute the subroutine server-side, where it doesn't exists.

To be able to execute the subroutine using PHP, it will have to exist on the server, not in the client browser.
Aug 30 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.