Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 28th, 2008, 10:44 PM
ravioliman's Avatar
Newbie
 
Join Date: Jul 2007
Posts: 6
Default Execute VBScript Subroutine from php

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.

Last edited by Atli; August 28th, 2008 at 10:57 PM. Reason: Added [code] tags.
Reply
  #2  
Old August 28th, 2008, 11:05 PM
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Age: 22
Posts: 2,777
Default

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.
Reply
  #3  
Old August 29th, 2008, 08:21 PM
ravioliman's Avatar
Newbie
 
Join Date: Jul 2007
Posts: 6
Default

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
Reply
  #4  
Old August 29th, 2008, 10:06 PM
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Age: 22
Posts: 2,777
Default

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.
Reply
  #5  
Old August 29th, 2008, 11:11 PM
ravioliman's Avatar
Newbie
 
Join Date: Jul 2007
Posts: 6
Default

Quote:
Originally Posted by Atli
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.
Reply
  #6  
Old August 30th, 2008, 04:01 PM
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Age: 22
Posts: 2,777
Default

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.
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles