Siebel VB Language Reference >

Language Overview


If you have never programmed in Visual Basic before, you may find the following hints helpful.

Declare your variables. As a general rule, use the Option Explicit statement, because it forces you to declare your variables (using the Dim statement) before you use them. Declaring your variables 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. 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 using 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 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 here.

Data Type
Symbol
Example
String
s
sName
Integer
i
iReturn
Long integer
l
lBigCount
Single-precision number
si
siAllowance
Double-precision number
d
dBudget
Object
o
oBusComp
Currency
c
cAmtOwed

You can also use suffix characters on your variable names, as described in Type Characters.

The Me object reference. The special object reference Me is a VB shorthand for "the current object." Use it in place of references to active Siebel 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
   ....
   End If
   BusComp_PreSetFieldValue = ContinueOperation
End Function

Trap errors. Especially in a LAN environment, where you cannot be sure that a record has not been changed or deleted by another user, you should create routines that keep the program from failing when it meets an unexpected condition. For more information about error-handling routines, read Error Handling.

Make effective use of the Select Case construct. Use the Select Case construct to choose among any number of alternatives your require, based on the value of a single variable. This is 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. For a full description of the Select Case construct, read Select Case Statement.

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

Set oBusComp = objBusObject.GetBusComp("Opportunity")
oBusComp.ClearToQuery
oBusComp.SetSearchSpec . . .
oBusComp.ExecuteQuery ForwardBackward
oBusComp.FirstRecord
oBusComp.NewRecord NewAfter
oBusComp.SetFieldValue "QuoteNumber", sQuoteId
oBusComp.SetFieldValue "Account", sAccount
. . .
sSolutionId(cSolution) = oBusComp.GetFieldValue( "Id" )
. . .

use the following:

Set oBusComp = objBusObject.GetBusComp("Opportunity")
With oBusComp
   .ClearToQuery
   .SetSearchSpec . . .   
   .ExecuteQuery ForwardBackward
   .FirstRecord
   .NewRecord NewAfter
   .SetFieldValue "QuoteNumber", sQuoteId
   .SetFieldValue "Account", sAccount
   . . .
   sSolutionId(cSolution) =.GetFieldValue( "Id" )
   . . .
End With

Use extreme care when working with date variables. When working with date variables, be careful with the date format. GetFieldValue returns the date in the format dd/mm/yyyy (followed by the time). The CVDate() function expects the regional setting. As a result, applying the CVDate() function to the return value may cause an error. The GetFormattedFieldValue method uses the regional settings of the user's operating system. The regional settings specify 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:

Here is an example:

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

When comparing date values, use the DateSerial function on the date values first. This makes sure that the values are in the same format so that the comparison is valid. Date values from different sources may be in different formats. DateSerial provides a uniform format for all dates. For example, you are checking to see if an employee's hire date is before a specific benefits changeover date. You should use the DateSerial function on both the hire date and the benefits changeover date, and then you can make a valid comparison between the two date values because they are in the same format.


 Siebel VB Language Reference
 Published: 18 June 2003