Siebel Object Interfaces Reference > Siebel Programming Tools >

About Siebel VB

If you have never programmed in Visual Basic before, you may want to start by reading Siebel VB Language Reference. It includes information on the internal VB program constructs, statements, and functions. You need to understand how these objects behave before you can program using the Siebel object methods and events.

Declare your variables. As a general rule, using the Option Explicit statement is helpful as it forces you to declare your variables (using the Dim statement) before you use them. Doing so makes it easier for others to understand your code, and for you to debug the code. You can declare a variable without giving it a data type, but if you do not specify a data type, Siebel VB assumes the type Variant, which requires 16 bytes—twice as much memory as the next smallest data type. If you can avoid Variant variables, you reduce the amount of memory required by your code, which may make execution faster. In Siebel VB, you place Option commands in the (general) (declarations) window.

Use standardized naming conventions. Another way to improve the readability of your code is to follow a set of standardized naming conventions. It does not really matter what conventions you follow as long as everyone in the programming group follows the same conventions. One very common convention is to prefix each variable with a letter denoting its type, as shown in Table 4.

Table 4. Naming Conventions for Variables in Scripts
Data Type







Long integer



Single-precision number



Double-precision number









You can also use suffix characters on your variable names.

Use the Me object reference. The special object reference Me is a VB shorthand for "the current object." You should use it in place of references to active business objects. For example, in a business component event handler, you should use Me in place of ActiveBusComp, as shown in the following example:

Function BusComp_PreSetFieldValue(FieldName As String, FieldValue As String) As Integer

If Val(Me.GetFieldValue("Rep %")) >75 Then
   TheApplication.RaiseErrorText("You cannot set the Rep% to greater than 75")
End If
BusComp_PreSetFieldValue = ContinueOperation

End Function

You can see other examples of Me in ParentBusComp Method, SetViewMode Method, BusComp_PreQuery Event, BusComp_PreWriteRecord Event, and ActiveMode Method.

Trap run-time errors. The standard VB methods return numeric error codes, which are documented in Siebel VB Language Reference. Siebel VB methods also may return error codes; however, they must be handled differently from those returned by the standard VB methods. For standard methods, you can use some combination of Err, ErrText, and Error. Siebel methods use numeric error codes in the range from 4000 to 4999. When you access Siebel object interfaces through COM or ActiveX, use a construct of this form to see the text of the error message.

If errCode <> 0 Then
   ErrText = GetLastErrText
   TheApplication.RaiseErrorText ErrText
   Exit Sub
End If

NOTE:  The GetLastErrText method is only available using interfaces external to Siebel Tools. Therefore, you can use it in Microsoft VB, but not in Siebel VB.

If you are working within the Siebel applications, especially in a LAN environment, where you cannot be sure that a record has not been changed or deleted by another user, create routines that keep the program from failing when it meets an unexpected condition. For information about error-handling routines, see the Language Overview topics in Siebel VB Language Reference.

Make effective use of the Select Case construct. The Select Case construct chooses among any number of alternatives you require, based on the value of a single variable. This is greatly preferable to a series of nested If statements, because it simplifies code maintenance and also improves performance because the variable must be evaluated only once.

Use the With shortcut. Use the With statement to apply several methods to a single object. It reduces typing and makes the code easier to read. Instead of a series of statements such as:

Set oBusObject = TheApplication.GetBusObject("Opportunity")
Set oBusComp = oBusObject.GetBusComp("Opportunity")
oBusComp.ActivateField "Account"
oBusComp.SetSearchSpec "Name", varname
oBusComp.ExecuteQuery ForwardBackward
If (oBusComp.FirstRecord = 1) Then
   sAccount = oBusComp.GetFieldValue "Account"
End If
. . .

use the following:

Set oBusObject = TheApplication.GetBusObject("Opportunity")
Set oBusComp = oBusObject.GetBusComp("Opportunity")
With oBusComp
   .ActivateField "Account"
   .SetSearchSpec "Name", varname
   .ExecuteQuery ForwardBackward
   If (.FirstRecord = 1) Then
      sAccount = .GetFieldValue "Account"
   End If
End With
. . .

Set oBusComp = Nothing
Set oBusObject = Nothing

Use extreme care when working with date variables. When working with date variables extreme care has to be taken regarding the date format. GetFieldValue always returns the date in dd/mm/yyyy format (eventually followed by the time). As a result, applying the CVDate() function, which expects the regional setting, to the return value may cause an error. The GetFormattedFieldValue method uses the regional settings of the user's operating system. The regional setting specifies the year with two digits in most cases, thereby creating the possibility of Y2K noncompliance. For these reasons, you should use the following approach for performing date arithmetic.

To perform date arithmetic

  1. Retrieve the value of date fields with the GetFieldValue method. For more information, read GetFieldValue Method.
  2. Convert it into a date variable using the DateSerial() function.
  3. Perform the required date arithmetic.

The following example is in Siebel VB:

Dim strDate as String, varDate as Variant
strDate = oBC.GetFieldValue("Date Field")
varDate =DateSerial(Val(Mid(strDate,7,4)),Val(Left(strDate,2)),_
[any date arithmetic]

Destroy any objects you have created when you no longer need them. While the interpreter takes care of object cleanup, it is a best practice to write code that explicitly destroys objects when they are no longer used. Explicit destruction of Siebel objects should occur in the procedure in which they are created.

To destroy objects in Siebel VB, set each object to Nothing in the reverse order of creation. Destroy child objects before parent objects. For example:

Set oBusObj = TheApplication.GetBusObject("contact")
Set oBusComp= oBusObj.GetBusComp("contact")

[ Your code here ]

Set oBusComp = Nothing
Set oBusObj = Nothing

Siebel Object Interfaces Reference Copyright © 2008, Oracle. All rights reserved.