Siebel VB Language Reference > VB Language Reference >

Set Statement

This standard VB statement assigns a COM object, such as an application, to a variable. Within Siebel Tools, it is used to create an instance of a Siebel object.


Set variableName = objectExpression



An object variable or variant variable


An expression that evaluates to an object—typically a function, an object member, or Nothing


Not applicable


The following example shows how to use the Set statement:

Dim COMObject As Object
Set COMObject = CreateObject("spoly.cpoly")

NOTE:  If you omit the keyword Set when assigning an object variable, Siebel VB tries to copy the default member of one object to the default member of another. This usually results in a run-time error:

' Incorrect code - tries to copy default member!
COMObject = GetObject("","spoly.cpoly")

Set differs from Let in that Let 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


This example creates an Opportunity Siebel business component outside the context of the user interface. The program prevents the user from deleting an account if there are opportunities associated with it. For details on the Siebel VB methods and objects used in this example, read 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"
      .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

See Also

CreateObject Function
Is Operator
Me Object
New Operator
Nothing Function
Object Class
Typeof Function

Siebel VB Language Reference