Programmer1974
Programmer
Hello all! I have posted this question in the VB Script forumn, but there wasn't an answer there to my question. Perhaps there is an XML solution that you guys can help me with! Here is the question...
I'm creating my own custom components (.wsc extension) and have included a method where I want to make some of the parameters optional. Below is how I call the method from a VB script and the component I created. This component is just for experimental purposes. It basically creates a CDO message and sends an e-mail via SMTP. With the CDO object in VB, the only required fields are the from and to addresses. I want to apply the same rules to my method. Here is how I call the method now:
Here is how I want to call the method:
Or even perhaps this:
Here is the component:
How can I modify my component to allow for optional parameters?
Is there a way to have XML supply default values if some are omitted from the call?
I'm fairly certain this can be done because if you create a type library (.tlb), you can go in to the object browser of a VB editor and see what methods are created by this component. You can also see which parameters are required and which are optional. If the limitation is on the VB side, then perhaps jscript can make this possible??
Thank you all for your help!
I'm creating my own custom components (.wsc extension) and have included a method where I want to make some of the parameters optional. Below is how I call the method from a VB script and the component I created. This component is just for experimental purposes. It basically creates a CDO message and sends an e-mail via SMTP. With the CDO object in VB, the only required fields are the from and to addresses. I want to apply the same rules to my method. Here is how I call the method now:
Code:
Set objSMTP = CreateObject("SMTP")
strReturn = objSMTP.SendNote("test@email", "test@email", "", "", "Test subject", "Test message", "", "")
Code:
Set objSMTP = CreateObject("SMTP")
strReturn = objSMTP.SendNote("test@email", "test@email")
Code:
Set objSMTP = CreateObject("SMTP")
strReturn = objSMTP.SendNote("test@email", "test@email", , , "Test subject", "Test message")
Code:
<package>
<?component error="true" debug="true"?>
<comment>
This component is used to send an e-mail via SMTP.
</comment>
<component id="SMTPEMail">
<object id="objEmail" progid="CDO.Message"/>
<registration
progid="SMTP"
description="This component sends an e-mail message via SMTP."
version="1.0"
clsid="{21D2D7E7-A67D-4B97-9F71-C027E173FC23}"/>
<public>
<method name="SendNote">
<parameter name="From" internalName="strFrom" />
<parameter name="To" internalName="strTo" />
<parameter name="CC" internalName="strCC" />
<parameter name="BCC" internalName="strBCC" />
<parameter name="Subject" internalName="strSubject" />
<parameter name="Body" internalName="strTextBody" />
<parameter name="HTMLBody" internalName="strHTMLBody" />
<parameter name="Attachments" internalName="strAttachments" />
</method>
</public>
<script language="VBScript">
Function SendNote(strFrom, strTo, strCC, strBCC, strSubject, strTextBody, strHTMLBody, strAttachments)
objEmail.From = strFrom
objEmail.To = strTo
objEmail.CC = strCC
objEmail.BCC = strBCC
objEmail.Subject = strSubject
If strTextBody > "" Then
objEmail.TextBody = strTextBody
Else
objEmail.HTMLBody = strHTMLBody
End If
If strAttachments > "" Then
objEmail.AddAttachment strAttachments
End If
objEmail.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
objEmail.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "[SMTP server]"
objEmail.Configuration.Fields.Update
On Error Resume Next
objEmail.Send
SendNote = Err.Number
End Function
</script>
</component>
</package>
Is there a way to have XML supply default values if some are omitted from the call?
I'm fairly certain this can be done because if you create a type library (.tlb), you can go in to the object browser of a VB editor and see what methods are created by this component. You can also see which parameters are required and which are optional. If the limitation is on the VB side, then perhaps jscript can make this possible??
Thank you all for your help!