34
Siebel Scripting, Siebel Scripting, Part Two Part Two Siebel VB Syntax Siebel VB Syntax

Siebel Scripting 2

Embed Size (px)

Citation preview

Page 1: Siebel Scripting 2

Siebel Scripting, Part Siebel Scripting, Part TwoTwo

Siebel VB SyntaxSiebel VB Syntax

Page 2: Siebel Scripting 2

IntroductionIntroduction

Data TypesData Types Dimensioning VariablesDimensioning Variables OperatorsOperators DecisionsDecisions LoopingLooping Functions and SubroutinesFunctions and Subroutines Arrays in Siebel VBArrays in Siebel VB Some Important VB MethodsSome Important VB Methods Using Siebel ObjectsUsing Siebel Objects Error Handling in Siebel VBError Handling in Siebel VB

Page 3: Siebel Scripting 2

Comments in Siebel VBComments in Siebel VB

Use an apostrophe ‘ At the Use an apostrophe ‘ At the beginning of a line to make a single beginning of a line to make a single line commentline comment

Example:Example: ‘‘This is a CommentThis is a Comment

There are NO multi-line comments in There are NO multi-line comments in Siebel VBSiebel VB

Page 4: Siebel Scripting 2

Data TypesData Types

Numbers: Integers, FractionsNumbers: Integers, Fractions StringsStrings Dates/TimesDates/Times VariantVariant ObjectsObjects

Object TypeObject Type Siebel Objects: BusComp, PropertySet, Siebel Objects: BusComp, PropertySet,

othersothers Siebel VB is a Siebel VB is a strong typedstrong typed language language

Page 5: Siebel Scripting 2

OperatorsOperators

Mathematical OperatorsMathematical Operators +, -, *, /, \, Mod, ^+, -, *, /, \, Mod, ^

Conditional OperatorsConditional Operators =, <>, <, >, <=, >==, <>, <, >, <=, >=

Logical OperatorsLogical Operators And, Or, NotAnd, Or, Not

AssignmentAssignment ==

Page 6: Siebel Scripting 2

Dimensioning VariablesDimensioning Variables

Syntax:Syntax: Dim VarName As DataTypeDim VarName As DataType

Examples:Examples: Dim iScore As IntegerDim iScore As Integer Dim bcContact As BusCompDim bcContact As BusComp

Can Dim more than one variable in one Can Dim more than one variable in one line:line: Dim sLastName, sFirstName As StringDim sLastName, sFirstName As String Only last variable gets specified data type: Only last variable gets specified data type:

others are type Variantothers are type Variant Cannot initializeCannot initialize

Page 7: Siebel Scripting 2

Decisions: IfDecisions: If

Syntax:Syntax: If Condition ThenIf Condition Then

‘‘Code to be executed if Condition is TrueCode to be executed if Condition is True End IfEnd If

Example:Example: If iScore < 60 ThenIf iScore < 60 Then

sGrade = “Fail”sGrade = “Fail” End IfEnd If

Simple Decision Making ConstructSimple Decision Making Construct

Page 8: Siebel Scripting 2

Decisions: Else Decisions: Else Syntax:Syntax:

If Condition ThenIf Condition Then ‘‘Code to Execute if Condition is TrueCode to Execute if Condition is True

ElseElse ‘‘Code to Execute if Condition is FalseCode to Execute if Condition is False

End IfEnd If Example:Example:

If iScore < 60 ThenIf iScore < 60 Then sGrade = “Fail”sGrade = “Fail”

ElseElse sGrade = “Passing”sGrade = “Passing”

End IfEnd If

Page 9: Siebel Scripting 2

Decisions: Else IfDecisions: Else If

Example:Example: If iScore < 60 ThenIf iScore < 60 Then

sGrade = “Fail”sGrade = “Fail” Else If iScore >= 100 ThenElse If iScore >= 100 Then

sGrade = “Perfect”sGrade = “Perfect” ElseElse

sGrade = “Passing”sGrade = “Passing” End IfEnd If

Page 10: Siebel Scripting 2

Decisions: Select CaseDecisions: Select Case

Used to make large nested if Used to make large nested if structures more readablestructures more readable

Syntax:Syntax: Select VarNameSelect VarName

Case FirstCaseCase FirstCase Case NextCaseCase NextCase Case ElseCase Else

End SelectEnd Select

Page 11: Siebel Scripting 2

Decisions: Select CaseDecisions: Select Case

Example:Example: Select Case iScoreSelect Case iScore

Case Is < 60Case Is < 60 sGrade = “Fail”sGrade = “Fail”

Case Is >= 100Case Is >= 100 sGrade = “Perfect”sGrade = “Perfect”

Case ElseCase Else sGrade = “Passing”sGrade = “Passing”

End SelectEnd Select

Page 12: Siebel Scripting 2

Looping: For LoopLooping: For Loop

Syntax:Syntax: For iCounter = iStart to iFinish Step For iCounter = iStart to iFinish Step

iAmountiAmount ‘‘Code to execute each iteration of loopCode to execute each iteration of loop

Next iCounterNext iCounter Example:Example:

For iCtr = 1 to 10 Step 2For iCtr = 1 to 10 Step 2 sStepNum = “Step Number: “ & Str$(iCtr)sStepNum = “Step Number: “ & Str$(iCtr)

Next iCtrNext iCtr

Page 13: Siebel Scripting 2

Looping: Do LoopLooping: Do Loop

Syntax:Syntax: DoDo

‘‘Code to execute each iteration of the loopCode to execute each iteration of the loop Loop Until (While) ConditionLoop Until (While) Condition

Example:Example: iCtr = 0iCtr = 0 DoDo

iCtr = iCtr + 1iCtr = iCtr + 1 sStepNum = “Step Number: “ & Str$(iCtr)sStepNum = “Step Number: “ & Str$(iCtr)

Loop Until iCtr = 10Loop Until iCtr = 10

Page 14: Siebel Scripting 2

Looping: While WendLooping: While Wend

Syntax:Syntax: While ConditionWhile Condition

‘‘Code to execute each iteration of the loopCode to execute each iteration of the loop WendWend

Example:Example: While sSRNum <> bcSR.GetFieldValue(“SR While sSRNum <> bcSR.GetFieldValue(“SR

Number”)Number”) bcSR.NextRecordbcSR.NextRecord

WendWend

Page 15: Siebel Scripting 2

Function And SubroutinesFunction And Subroutines

A Function returns a valueA Function returns a value A Subroutine does notA Subroutine does not Either can have data passed into Either can have data passed into

them as parametersthem as parameters Use ByVal or ByRefUse ByVal or ByRef By default, Objects are passed by By default, Objects are passed by

referencereference Simple data types are passed by valueSimple data types are passed by value

Page 16: Siebel Scripting 2

SubroutinesSubroutines

Syntax:Syntax: Sub SubName (Var1 as Type, Var2 as Sub SubName (Var1 as Type, Var2 as

Type)Type) ‘‘Code to execute inside functionCode to execute inside function

End SubEnd Sub Example:Example:

Sub SetName (sName as String)Sub SetName (sName as String) TheApplication.SetProfileAttr “SPN_CA_NAME”, TheApplication.SetProfileAttr “SPN_CA_NAME”,

sNamesName End SubEnd Sub

Page 17: Siebel Scripting 2

Calling SubroutinesCalling Subroutines

Syntax:Syntax: Call SubName Value1, Value2Call SubName Value1, Value2 ‘‘Call Keyword is optionalCall Keyword is optional

Examples:Examples: Call SetName “George Bush”Call SetName “George Bush” SetName “George Bush”SetName “George Bush”

Page 18: Siebel Scripting 2

FunctionsFunctions

Syntax:Syntax: Function FuncName (Var1 as Type) As Function FuncName (Var1 as Type) As

TypeType ‘‘Code to execute inside functionCode to execute inside function ‘‘Use FuncName = ReturnVal to return a Use FuncName = ReturnVal to return a

valuevalue End FunctionEnd Function

Page 19: Siebel Scripting 2

FunctionsFunctions

Example:Example: Function GetName () As StringFunction GetName () As String

Dim sName As StringDim sName As String sName = GetProfileAttr(“SPN_CA_NAME”)sName = GetProfileAttr(“SPN_CA_NAME”) GetName = sNameGetName = sName

End FunctionEnd Function

Page 20: Siebel Scripting 2

Calling FunctionsCalling Functions

Syntax:Syntax: Var = FuncName(Value)Var = FuncName(Value) SubName (FuncName(Value))SubName (FuncName(Value))

Example:Example: Dim sName as StringDim sName as String sName = GetNamesName = GetName

Example 2:Example 2: FindValue(GetName)FindValue(GetName) ‘‘FindValue is some other sub that takes a FindValue is some other sub that takes a

string as a parameterstring as a parameter

Page 21: Siebel Scripting 2

ArraysArrays

Dimensioning:Dimensioning: Dim ArrayName (NumElements) As TypeDim ArrayName (NumElements) As Type

Max 60 elementsMax 60 elements Arrays can be multi-dimensionalArrays can be multi-dimensional Useful methods for arraysUseful methods for arrays

ReDim: Used for dynamic arraysReDim: Used for dynamic arrays LBound, UBound: Return lower or upper LBound, UBound: Return lower or upper

bound of arraybound of array Erase: Reinitialize arrayErase: Reinitialize array

Page 22: Siebel Scripting 2

Some Important VB MethodsSome Important VB Methods

NowNow AscAsc ValVal Str$Str$ Left$, Mid$, Right$Left$, Mid$, Right$ File Handling in Siebel VBFile Handling in Siebel VB

Page 23: Siebel Scripting 2

NowNow

Returns Current Time and Date on Returns Current Time and Date on machine that the script is running onmachine that the script is running on Running Web Client or Wireless Web Running Web Client or Wireless Web

Client, that is the Siebel Server that the Client, that is the Siebel Server that the AOM is running onAOM is running on

Running Mobile Web Client or Dedicated Running Mobile Web Client or Dedicated Web Client, that is the machine that Web Client, that is the machine that Siebel.exe is running on- the client’s Siebel.exe is running on- the client’s machinemachine

Page 24: Siebel Scripting 2

AscAsc

Takes a string as argumentTakes a string as argument Returns the ASCII value of the first Returns the ASCII value of the first

char in the stringchar in the string Useful for determining whether input Useful for determining whether input

is valid – you can check to see if it is is valid – you can check to see if it is an alphabetic character, a numeric an alphabetic character, a numeric character, or anything elsecharacter, or anything else

Page 25: Siebel Scripting 2

Val and Str$Val and Str$

Val takes a String argument that is Val takes a String argument that is made up of numbers (i.e. “10”) and made up of numbers (i.e. “10”) and returns its numeric valuereturns its numeric value

Str$ takes a numeric argument and Str$ takes a numeric argument and converts it to a stringconverts it to a string

Page 26: Siebel Scripting 2

String ManipulationString Manipulation

Left$ Takes a string and an integer Left$ Takes a string and an integer argumentargument

Returns a substring of the string Returns a substring of the string passed inpassed in

Right$ is same, but returns the Right$ is same, but returns the substring from the rightsubstring from the right

Mid$ Takes a string and 2 integers. It Mid$ Takes a string and 2 integers. It returns a substring of the length of returns a substring of the length of the second integer, starting at the the second integer, starting at the character indicated by the first integercharacter indicated by the first integer

Page 27: Siebel Scripting 2

File HandlingFile Handling

Open StatementOpen Statement Line Input StatementLine Input Statement Eof FunctionEof Function Write StatementWrite Statement Close StatementClose Statement

Page 28: Siebel Scripting 2

Opening FilesOpening Files

Syntax:Syntax: Open “Path\Filename” For Input (Output) Open “Path\Filename” For Input (Output)

As #As # Examples:Examples:

Open “C:\MyFile.txt” For Input As #1Open “C:\MyFile.txt” For Input As #1 Open “.\log\Error.log” For Output as #3Open “.\log\Error.log” For Output as #3

Page 29: Siebel Scripting 2

Reading From FilesReading From Files

Easiest to Use Line Input StatementEasiest to Use Line Input Statement See Also: Input Stmt, Input Function, Get See Also: Input Stmt, Input Function, Get

StmtStmt Syntax:Syntax:

Line Input #FileNum, VarNameLine Input #FileNum, VarName Example:Example:

Open “C\MyFile.txt” For Input As #1Open “C\MyFile.txt” For Input As #1 Do While Not Eof(1)Do While Not Eof(1)

Line Input #1, sTempLine Input #1, sTemp #sXML = sXML & sTemp#sXML = sXML & sTemp

LoopLoop Close #1Close #1

Page 30: Siebel Scripting 2

Eof FunctionEof Function

Takes the number of an open file as Takes the number of an open file as argumentargument

Returns true if file pointer is at the Returns true if file pointer is at the end of the fileend of the file

Page 31: Siebel Scripting 2

Write StatementWrite Statement

Writes Data to an open fileWrites Data to an open file Syntax:Syntax:

Write #FileNum, ValueWrite #FileNum, Value Example:Example:

Open “C:\MyFile.txt” For Output As #2Open “C:\MyFile.txt” For Output As #2 For iCtr = 0 to UBound(MyArray)For iCtr = 0 to UBound(MyArray)

Write #2, MyArray(iCtr)Write #2, MyArray(iCtr) Next iCtrNext iCtr

Close #2Close #2

Page 32: Siebel Scripting 2

Close StatementClose Statement

Always Make sure to close your files Always Make sure to close your files after use!after use!

Syntax: Syntax: Close #FileNumClose #FileNum

Page 33: Siebel Scripting 2

Siebel Specific ObjectsSiebel Specific Objects

BusCompBusComp BusObjectBusObject TheApplicationTheApplication PropertySetPropertySet ServiceService ObjectObject

Page 34: Siebel Scripting 2

Error Handling in Siebel VBError Handling in Siebel VB

Syntax:Syntax: On Error GoTo Label:On Error GoTo Label: ‘‘other codeother code Label:Label:

‘‘Handle error hereHandle error here

Example:Example: On Error GoTo ErrHandler:On Error GoTo ErrHandler: ‘‘other codeother code ErrHandler:ErrHandler:

‘‘Handle error hereHandle error here