Service Functions – String (QTP, VBScript)
Posted by Albert Gareev on 2009/10/01
In the code examples I present I often refer to routine functions.
In my framework I have specialized libraries to call from. In my blog I have been providing them along with the posts but now I see that better to keep all in one place and “call” with the link.
Matching string with a pattern (Regular Expression, RegEx)
Public Function Regex_Test(ByVal strSrc, ByVal strRegEx) Dim objRegEx Dim boolRC, intRC Set objRegEx = New RegExp objRegEx.Pattern = strRegEx On Error Resume Next boolRC = objRegEx.Test(strSrc) intRC = Err.Number On Error GoTo 0 If intRC <> 0 Then boolRC = FALSE Set objRegEx = Nothing Regex_Test = boolRC End Function
Replace pattern(s) in a string
Public Function ReplaceEx(ByVal sSource, ByVal sPattern, ByVal sDest, ByVal boolMatchCase) Dim objRegExp Set objRegExp = new RegExp objRegExp.Global = TRUE objRegExp.IgnoreCase = Not boolMatchCase objRegExp.Pattern = sPattern ReplaceEx = objRegExp.Replace(sSource, sDest) Set objRegExp = Nothing End Function
Number conversion and initialization with a default value
Public Function IntVal(ByVal sVal) If isNumeric(sVal) Then IntVal = CLng(sVal) Else IntVal = 0 End If End Function Public Function InitLong(ByVal sActualValue, ByVal DefaultValue) DefaultValue = IntVal(DefaultValue) If sActualValue = "" Then InitLong = DefaultValue Else If isNumeric(sActualValue) Then InitLong = CLng(sActualValue) Else InitLong = DefaultValue End If End If End Function
Initialize string with a default value
Public Function InitValue(ByVal sActualValue, ByVal DefaultValue) If sActualValue = "" Then InitValue = DefaultValue Else InitValue = sActualValue End If End Function
Initialize boolean with a default value
Public Function InitBool(ByVal sActualValue, ByVal boolDefaultValue) sActualValue = UCase(sActualValue) Select Case boolDefaultValue Case TRUE 'By default set to TRUE 'Set to FALSE if explicitely defined If (sActualValue = "FALSE") OR (sActualValue = "NO") Then InitBool = FALSE Else InitBool = TRUE End If Case FALSE 'By default set to FALSE 'Set to TRUE if explicitely defined If (sActualValue = "TRUE") OR (sActualValue = "YES") Then InitBool = TRUE Else InitBool = FALSE End If End Select End Function
DotNetFactory interface functions (4) – Create GUI Form « Automation Beyond said
[...] Service Functions – String (QTP, VBScript) [...]
Text File compare in “WDIFF” style (QTP, VBScript, XML, XSL) « Automation Beyond said
[...] ReplaceEx function source code: Service Functions – String (QTP, VBScript) [...]
DotNetFactory interface functions (1) – Create Button « Automation Beyond said
[...] Service Functions – String (QTP, VBScript) [...]
DotNetFactory interface functions (2) – Create Label « Automation Beyond said
[...] Service Functions – String (QTP, VBScript) [...]
DotNetFactory interface functions (3) – Create TextBox « Automation Beyond said
[...] Service Functions – String (QTP, VBScript) [...]
DotNetFactory interface functions (4) – Create CheckBox « Automation Beyond said
[...] Service Functions – String (QTP, VBScript) [...]
DotNetFactory interface functions (5) – Create ComboBox « Automation Beyond said
[...] Service Functions – String (QTP, VBScript) [...]
DotNetFactory interface functions – create custom dialog « Automation Beyond said
[...] Service Functions – String (QTP, VBScript) [...]
Overload your VBScript functions (My article on QAGuild) « Automation Beyond said
[...] Service Functions – String (QTP, VBScript) [...]
Generating text file from XML template (QTP, VBScript) « Automation Beyond said
[...] Used resources: Service Functions – String (QTP, VBScript) [...]
GP/QTP Automation: interface class for Excel.VBA macro « Automation Beyond said
[...] Used resources: Service Functions – String (QTP, VBScript) [...]
GUI object synchronization – custom function (QTP, VBScript) « Automation Beyond said
[...] Used resources: Service Functions – String (QTP, VBScript) [...]