CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Simple VBScript to PHP

Print topic Send  topic

Author Message
TonyReid


Posts: 159
Posted: 01/25/2007, 3:45 AM

Hi,

Im trying to convert this seemingly simple vbscript code to php.

All it does is add a task in the users Microsoft Outlook.

This code in vbscript works fine in Internet Explorer (which is what I need it to work in )

  
<script type="text/vbscript">  
  
Const olTaskItem = 3  
Set objOutlook = CreateObject("Outlook.Application")  
Set objTask = objOutlook.CreateItem(olTaskItem)  
  
objTask.Subject = "Things to Do"  
objTask.Body = "Dont forget to make a cup of Tea"  
objTask.ReminderSet = True  
objTask.ReminderTime = #31/12/2006 12:00 PM#  
objTask.DueDate = #31/12/2006 12:00 PM#   
  
objTask.Save  
</script>   

This conversion to PHP should work... but it doesnt :(

  
<?php  
  
$olTaskItem = 3;  
$objOutlook = new COM("Outlook.Application");  
$objTask = $objOutlook->CreateItem($olTaskItem);  
  
$objTask->Subject = "Things to Do";  
$objTask->Body = "Dont forget to make a cup of Tea";  
$objTask->ReminderSet= True;  
$objTask->ReminderTime = '#10/10/2005 12:00 PM#';  
$objTask->DueDate = '#31/12/2006 12:00 PM#'  
  
$task->Save();  
  
?>  
  

As I need to pass variables from php to the vbscript - I cant see this working unless I can get the above php code to work.

Any ideas really and truly appreciated.

Thanks in advance,
Tony

_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk
View profile  Send private message
DonB
Posted: 01/25/2007, 7:51 AM

I don't think the octothorpes ('pound signs' ;-) shouldn't be there. That's
an ancient quirky Access database/ODBC delimiter that Microsoft came up
with. I don't remember the last time I used that. Just enclose the dates
in apostrophes and (assuming nothing else is screwy) it should work fine.

--
DonB

http://www.gotodon.com/ccbth


"TonyReid" <TonyReid@forum.codecharge> wrote in message
news:545b8986d15378@news.codecharge.com...
> Hi,
>
> Im trying to convert this seemingly simple vbscript code to php.
>
> All it does is add a task in the users Microsoft Outlook.
>
> This code in vbscript works fine in Internet Explorer (which is what I
need it
> to work in )
>
>
  
> <script type="text/vbscript">  
>  
> Const olTaskItem = 3  
> Set objOutlook = CreateObject("Outlook.Application")  
> Set objTask = objOutlook.CreateItem(olTaskItem)  
>  
> objTask.Subject = "Things to Do"  
> objTask.Body = "Dont forget to make a cup of Tea"  
> objTask.ReminderSet = True  
> objTask.ReminderTime = #31/12/2006 12:00 PM#  
> objTask.DueDate = #31/12/2006 12:00 PM#  
>  
> objTask.Save  
> </script>  
> 
>
> This conversion to PHP should work... but it doesnt :(
>
>
  
> <?php  
>  
> $olTaskItem = 3;  
> $objOutlook = new COM("Outlook.Application");  
> $objTask = $objOutlook->CreateItem($olTaskItem);  
>  
> $objTask->Subject = "Things to Do";  
> $objTask->Body = "Dont forget to make a cup of Tea";  
> $objTask->ReminderSet= True;  
> $objTask->ReminderTime = '#10/10/2005 12:00 PM#';  
> $objTask->DueDate = '#31/12/2006 12:00 PM#'  
>  
> $task->Save();  
>  
> ?>  
>  
> 
>
> As I need to pass variables from php to the vbscript - I cant see this
working
> unless I can get the above php code to work.
>
> Any ideas really and truly appreciated.
>
> Thanks in advance,
> Tony
>
> _________________
> Using: CodeCharge Studio 3.0 - IIS, PHP and MSSQL
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

TonyReid


Posts: 159
Posted: 01/25/2007, 8:00 AM

Thanks Don,

I did try that - but it doesnt make any difference :(


_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk
View profile  Send private message
ejay

Posts: 17
Posted: 01/26/2007, 1:53 AM

I am not sure of what you want to do: I assume the following, tell me if it is correct:

1/ you have a web application in code charge studio that is using php

2/ you want your users when they open a specific web page to have outlook on the user's machine create a new outlook task item whith some parameters coming from the web application

3/ you are looking for a way to pass these parameters from the web application in php to the user's outlook application

If my assumptions above are correct I may go further in describing a solution
_________________
Eric Jay
web solutions using CodeCharge studio
View profile  Send private message
TonyReid


Posts: 159
Posted: 01/26/2007, 1:58 AM

Hi Eric,

That is exactly what I need to happen.

The user will click a button and that will call the script to add a task to the users outlook.

Thanks for any suggestions you may have.

Tony

_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk
View profile  Send private message
lwismanuel


Posts: 39
Posted: 01/26/2007, 3:07 AM

Make sure that the COM object is been create nad COM must be enable in the php.ini. I have also noticed that you are missing a semicolon at line #11.

Try this in PHP5:
<?php    
    
$olTaskItem = 3;  
  
try  
	{    
		$objOutlook = new COM('Outlook.Application');  
	} catch (Exception $e) {  
			die($e->getMessage());  
	}  
  
$objTask = $objOutlook->CreateItem($olTaskItem);    
  
$objTask->Subject = 'Things to Do';    
$objTask->Body = 'Dont forget to make a cup of Tea';    
$objTask->ReminderSet= True;    
$objTask->ReminderTime = '10/10/2005 12:00 PM';    
$objTask->DueDate = '31/12/2006 12:00 PM';    
    
$task->Save();    
    
?> 
View profile  Send private message
TonyReid


Posts: 159
Posted: 01/26/2007, 3:17 AM

That doesnt work either - perhaps its something to do with php.ini?

Here is the com section of php.ini

Quote :

[COM]
; path to a file containing GUIDs, IIDs or filenames of files with TypeLibs
;com.typelib_file =
; allow Distributed-COM calls
com.allow_dcom = true
; autoregister constants of a components typlib on com_load()
com.autoregister_typelib = true
; register constants casesensitive
com.autoregister_casesensitive = false
; show warnings on duplicate constat registrations
com.autoregister_verbose = true


_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk
View profile  Send private message
ejay

Posts: 17
Posted: 01/26/2007, 4:09 AM

this may work, give it a try (I am not very familiar with vbscript)

1/ first put this code in the html template of your code charge studio page:

  
<script type="text/vbscript">    
  
function AddAnOutlookTask(Subject , Body , ReminderTime, DueDate  )  
  
Const olTaskItem = 3    
Set objOutlook = CreateObject("Outlook.Application")    
Set objTask = objOutlook.CreateItem(olTaskItem)    
    
objTask.Subject = Subject   
objTask.Body = Body  
objTask.ReminderSet = True    
objTask.ReminderTime = ReminderTime     
objTask.DueDate = DueDate      
    
objTask.Save    
  
AddAnOutlookTask=false ' this to make sure that clicking the button does not submit the page back to the server  
  
end function  
</script>   

Next, on your code charge page button goto to the "format" tab of the properties window, open the "events" list and on the "onclick" property type the following (be carefull to put ' and { and } as shown)
  
AddAnOutlookTask('{SubjectParam}', '{BodyParam}' , '{ReminderTimeParam}', '{DueDateParam}'  )  

The above will configure the button as follows in the html template of your code charge page (assuming the button is named "AddAnOutlookTaskButton". You may want to double check

Quote :
<!-- BEGIN Button AddAnOutlookTaskButton -->
<input onclick="AddAnOutlookTask('{SubjectParam}', '{BodyParam}' , '{ReminderTimeParam}', '{DueDateParam}' )
" type="submit" value="Add an Outlook task" name="{Button_Name}">
<!-- END Button AddAnOutlookTaskButton -->


Finally, add a "before show" (php) custom code to your button with this custom code:
  
global $Tpl;  
$Tpl->setvar('SubjectParam',whatevervalueforSubjectParam);  
$Tpl->setvar('BodyParam',whatevervalueforBodyParam);  
$Tpl->setvar('ReminderTimeParam',whatevervalueforReminderTimeParam);  
$Tpl->setvar('DueDateParam',whatevervalueforDueDateParam);  
  

$Tpl->setvar is documented in code charge studio documentation

That should do the trick - (there may be errors in the above code as I did not test it)
_________________
Eric Jay
web solutions using CodeCharge studio
View profile  Send private message
TonyReid


Posts: 159
Posted: 01/26/2007, 5:24 AM

Well it looks like its about to work - but when clicking the button I get the IE error - Cannot Use Parentheses when calling a sub.
_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk
View profile  Send private message
Claudio Morinico
Posted: 01/26/2007, 8:49 AM


Tony,

Try to put it this way:

AddAnOutlookTask '{SubjectParam}', '{BodyParam}', '{ReminderTimeParam}',
'{DueDateParam}'

(the same as before without the starting and ending parenthesis).

This is a common error in Visual Basic language. If you are not going to
return the result of the function to a variable, then you must call the
function as a sub (without parenthesis).

Best Regards,

--
Claudio Morinico,
Montevideo - Uruguay.

El dia Fri, 26 Jan 2007 5:24:27 -0800, TonyReid
(TonyReid@forum.codecharge) dijo...
> Well it looks like its about to work - but when clicking the button I get the IE
> error - Cannot Use Parentheses when calling a sub.
> _________________
> Using: CodeCharge Studio 3.0 - IIS, PHP and MSSQL
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
>
ejay

Posts: 17
Posted: 01/26/2007, 9:45 AM

you may also try
  
returnValue=AddAnOutlookTask('{SubjectParam}', '{BodyParam}' , '{ReminderTimeParam}', '{DueDateParam}'  )  
as i am under the impression you must return a value "false" to the onclick event in order to make sure your page is not submitted back to the server, which is normally required since the button is to perform an action on the user's machine, not on the web site
_________________
Eric Jay
web solutions using CodeCharge studio
View profile  Send private message
TonyReid


Posts: 159
Posted: 01/26/2007, 3:19 PM

Thanks for your help with this guys - it really is appreciated :)

I'll try the other suggestions when I get back to the office on monday.

Thanks again,
Tony

_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk
View profile  Send private message
ejay

Posts: 17
Posted: 01/29/2007, 12:48 AM

I have been "googling" VBSCRIPT for you; it seems the default langugage for scripts is JScript, not VBscript.

If that is the case I would recommend adding a language="VBscript" attribute to the button, so you would have something like

  
<input language="VBscript"  onclick="AddAnOutlookTask('{SubjectParam}', '{BodyParam}' , '{ReminderTimeParam}', '{DueDateParam}' )  
" type="submit" value="Add an Outlook task" name="{Button_Name}">  
  

From what I see, calling a VBSCRIPT function in an onclick event does not seem to be a problem. So make sure you declared a function, not a sub.

I dont know if it helps, but it might - good luck
_________________
Eric Jay
web solutions using CodeCharge studio
View profile  Send private message
TonyReid


Posts: 159
Posted: 01/29/2007, 2:33 AM

I think this is getting close.... I tried the above suggestions and am now getting an error on click..

Type Mismatch: Unable to coerce parameter value. Outlook cannot translate your string.




_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk
View profile  Send private message
TonyReid


Posts: 159
Posted: 01/29/2007, 2:50 AM

Hey it works if I swap out the variables in the return value...


returnValue=AddAnOutlookTask('Things to Do', 'Dont forget to make a cup of Tea' , '10/10/2005 12:00 PM', '31/12/2006 12:00 PM' )
_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.