Siebel Scripting, Part Two Siebel VB Syntax
Introduction
Data Types Dimensioning Variables Operators Decisions Looping Functions and Subroutines Arrays in Siebel VB Some Important VB Methods Using Siebel Objects Error Handling in Siebel VB
Comments in Siebel VB
Use an apostrophe ‘ At the beginning of a line to make a single line comment Example:
‘This is a Comment
There are NO multi-line comments in Siebel VB
Data Types
Numbers: Integers, Fractions Strings Dates/Times Variant Objects
Object Type Siebel Objects: BusComp, PropertySet, others
Siebel VB is a strong typed language
Operators
Mathematical Operators
Conditional Operators
=, <>, <, >, <=, >=
Logical Operators
+, -, *, /, \, Mod, ^
And, Or, Not
Assignment
=
Dimensioning Variables
Syntax:
Examples:
Dim iScore As Integer Dim bcContact As BusComp
Can Dim more than one variable in one line:
Dim VarName As DataType
Dim sLastName, sFirstName As String Only last variable gets specified data type: others are type Variant
Cannot initialize
Decisions: If
Syntax:
If Condition Then
End If
Example:
If iScore < 60 Then
‘Code to be executed if Condition is True
sGrade = “Fail”
End If
Simple Decision Making Construct
Decisions: Else
Syntax:
If Condition Then
Else
‘Code to Execute if Condition is True ‘Code to Execute if Condition is False
End If
Example:
If iScore < 60 Then
Else
sGrade = “Fail” sGrade = “Passing”
End If
Decisions: Else If
Example:
If iScore < 60 Then
Else If iScore >= 100 Then
sGrade = “Perfect”
Else
sGrade = “Fail”
sGrade = “Passing”
End If
Decisions: Select Case
Used to make large nested if structures more readable Syntax:
Select VarName Case FirstCase Case NextCase Case Else
End Select
Decisions: Select Case
Example: Select Case iScore
Case Is < 60
Case Is >= 100
sGrade = “Perfect”
Case Else
sGrade = “Fail”
sGrade = “Passing”
End Select
Looping: For Loop
Syntax:
For iCounter = iStart to iFinish Step iAmount
‘Code to execute each iteration of loop
Next iCounter
Example:
For iCtr = 1 to 10 Step 2
sStepNum = “Step Number: “ & Str$(iCtr)
Next iCtr
Looping: Do Loop
Syntax:
Do
‘Code to execute each iteration of the loop
Loop Until (While) Condition
Example:
iCtr = 0 Do iCtr = iCtr + 1 sStepNum = “Step Number: “ & Str$(iCtr)
Loop Until iCtr = 10
Looping: While Wend
Syntax:
While Condition
‘Code to execute each iteration of the loop
Wend
Example:
While sSRNum <> bcSR.GetFieldValue(“SR Number”)
bcSR.NextRecord
Wend
Function And Subroutines
A Function returns a value A Subroutine does not Either can have data passed into them as parameters
Use ByVal or ByRef By default, Objects are passed by reference Simple data types are passed by value
Subroutines
Syntax:
Sub SubName (Var1 as Type, Var2 as Type)
‘Code to execute inside function
End Sub
Example:
Sub SetName (sName as String)
TheApplication.SetProfileAttr “SPN_CA_NAME”, sName
End Sub
Calling Subroutines
Syntax:
Call SubName Value1, Value2 ‘Call Keyword is optional
Examples:
Call SetName “George Bush” SetName “George Bush”
Functions
Syntax:
Function FuncName (Var1 as Type) As Type ‘Code to execute inside function ‘Use FuncName = ReturnVal to return a value
End Function
Functions
Example:
Function GetName () As String Dim sName As String sName = GetProfileAttr(“SPN_CA_NAME”) GetName = sName
End Function
Calling Functions
Syntax:
Example:
Var = FuncName(Value) SubName (FuncName(Value)) Dim sName as String sName = GetName
Example 2:
FindValue(GetName) ‘FindValue is some other sub that takes a string as a parameter
Arrays
Dimensioning:
Dim ArrayName (NumElements) As Type
Max 60 elements Arrays can be multi-dimensional Useful methods for arrays
ReDim: Used for dynamic arrays LBound, UBound: Return lower or upper bound of array Erase: Reinitialize array
Some Important VB Methods
Now Asc Val Str$ Left$, Mid$, Right$ File Handling in Siebel VB
Now
Returns Current Time and Date on machine that the script is running on
Running Web Client or Wireless Web Client, that is the Siebel Server that the AOM is running on Running Mobile Web Client or Dedicated Web Client, that is the machine that Siebel.exe is running on- the client’s machine
Asc
Takes a string as argument Returns the ASCII value of the first char in the string Useful for determining whether input is valid – you can check to see if it is an alphabetic character, a numeric character, or anything else
Val and Str$
Val takes a String argument that is made up of numbers (i.e. “10”) and returns its numeric value Str$ takes a numeric argument and converts it to a string
String Manipulation
Left$ Takes a string and an integer argument Returns a substring of the string passed in Right$ is same, but returns the substring from the right Mid$ Takes a string and 2 integers. It returns a substring of the length of the second integer, starting at the character indicated by the first
File Handling
Open Statement Line Input Statement Eof Function Write Statement Close Statement
Opening Files
Syntax:
Open “Path\Filename” For Input (Output) As #
Examples:
Open “C:\MyFile.txt” For Input As #1 Open “.\log\Error.log” For Output as #3
Reading From Files
Easiest to Use Line Input Statement
Syntax:
See Also: Input Stmt, Input Function, Get Stmt Line Input #FileNum, VarName
Example:
Open “C\MyFile.txt” For Input As #1
Do While Not Eof(1)
Line Input #1, sTemp #sXML = sXML & sTemp
Loop
Close #1
Eof Function
Takes the number of an open file as argument Returns true if file pointer is at the end of the file
Write Statement
Writes Data to an open file Syntax:
Write #FileNum, Value
Example:
Open “C:\MyFile.txt” For Output As #2
For iCtr = 0 to UBound(MyArray)
Write #2, MyArray(iCtr)
Next iCtr
Close #2
Close Statement
Always Make sure to close your files after use! Syntax:
Close #FileNum
Siebel Specific Objects
BusComp BusObject TheApplication PropertySet Service Object
Error Handling in Siebel VB
Syntax:
On Error GoTo Label: ‘other code Label:
‘Handle error here
Example:
On Error GoTo ErrHandler: ‘other code ErrHandler:
‘Handle error here