Assign COM Object Statement
The Assign COM Object statement assigns a COM object, such as an application, to a variable. In Siebel Tools, you can use it to create an instance of a Siebel object. It does not return a value. The Assign COM Object statement differs from the Let statement. The Let statement assigns an expression to a Siebel VB variable. For example:
Set o1 = o2. Sets the object reference.
Let o1 = o2 . Sets the value of the default member.
Format
Set variableName = objectExpression
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
variableName |
An object variable or variant variable. |
objectExpression |
An expression that evaluates to an object. This object is typically one of the following items:
|
Including the Set Keyword When You Assign an Object Variable
If you do not include the Set keyword when you assign an object variable, then Siebel VB attempts to copy the default member of one object to the default member of another object. This situation typically results in the following run-time error:
' Incorrect code - tries to copy default member!
COMObject = GetObject("","spoly.cpoly")
The following example uses the Assign COM Object statement:
Dim COMObject As Object
Set COMObject = CreateObject("spoly.cpoly")
COMObject.reset
The following example creates an Opportunity business component outside the context of the user interface. The code prevents the user from deleting an account if there are opportunities associated with it. For more information about the Siebel VB methods and objects that this example uses, see Siebel Object Interfaces Reference:
Function BusComp_PreDeleteRecord As Integer
Dim iReturn as integer
Dim oBC as BusComp
Dim oBO as BusObject
Dim sAcctRowId as string
iReturn = ContinueOperation
sAcctRowId = me.GetFieldValue("Id")
set oBO = theApplication.GetBusObject("Opportunity")
set oBC = oBO.GetBusComp("Opportunity")
With oBC
.SetViewMode AllView
.ActivateField "Account Id"
.ClearToQuery
.SetSearchSpec "Account Id", sAcctRowId
.ExecuteQuery ForwardOnly
if (.FirstRecord) = 1 then
‘Opportunities exist for the Account - Delete is not allowed
iReturn = CancelOperation
end if
End With
BusComp_PreDeleteRecord = iReturn
Set oBC = Nothing
Set oBO = Nothing
End Function