‘Three different versions of blnStrComp

 

'********************************************************************

'*

'* Function blnStrComp

'*

'*   Author: NetworkAdminKB.com

'*  Created: 2008-05-18

'* Modified: 2008-05-18

'*

'* Purpose: Returns a boolean indicating if the strings provided are

'*            equal based on case sensitive or case insensitive

'*            comparison.  Numbers are converted to strings for

'*            comparison.

'*

'* Input:   strComp1  A string to compare with strComp2

'*          strComp2  A string to compare with strComp1

'*          blnCase   A boolean indicating case sensitive comparisons.

'*                      True  = Case Sensitive comparison

'*                      False = Case Insensitive comparison (Default)

'*

'*  Notes: UCase and LCase convert numbers to strings for comparison

'*

'* Output:  Returns a boolean indicating if the strings provided are

'*            equal based on case sensitive or case insensitive

'*            comparison.

'*            True  = The strings are equal

'*            False = The strings are not equal.

'*

'* Calls:

'* ReturnCaseComparisonValue

'********************************************************************

Function blnStrComp(ByVal strComp1, ByVal strComp2, ByVal blnCase)

  'Version 1.0 2008-05-18

 

  Select Case StrComp(strComp1, strComp2, ReturnCaseComparisonValue(blnCase))

    Case 0

      blnStrComp = True

    Case Null, -1, 1

      blnStrComp = False

    Case Else

      'Return Default Value

      blnStrComp = False

  End Select 'StrComp(strComp1, strComp2, ReturnCaseComparisonValue(blnCase))

End Function 'blnStrComp

 

 

'********************************************************************

'*

'* Function blnStrComp

'*

'*   Author: NetworkAdminKB.com

'*  Created: 2008-05-18

'* Modified: 2008-05-29

'*

'* Purpose: Returns a boolean indicating if the strings provided are

'*            equal based on case sensitive or case insensitive

'*            comparison.  Numbers are converted to strings for

'*            comparison.

'*

'* Input:   strComp1  A string to compare with strComp2

'*          strComp2  A string to compare with strComp1

'*          blnCase   A boolean indicating case sensitive comparisons.

'*                      True  = Case Sensitive comparison

'*                      False = Case Insensitive comparison (Default)

'*

'* Output:  Returns a boolean indicating if the strings provided are

'*            equal based on case sensitive or case insensitive

'*            comparison.

'*            True  = The strings are equal

'*            False = The strings are not equal.

'*

'*  Notes: UCase and LCase convert numbers to strings for comparison

'*

'* Changes:

'* 2008-05-29: Complete re-write not using StrComp function to

'*               improve speed.

'********************************************************************

Function blnStrComp(ByVal strComp1, ByVal strComp2, ByVal blnCase)

  'Version 2.0 2008-05-29

 

  Select Case blnCase

    Case True

      'case sensitive comparison

       blnStrComp = CBool(strComp1 = strComp2)

    Case False

      'case insensitive comparison

      blnStrComp = CBool(UCase(strComp1) = UCase(strComp2))

    Case Else

      'Default case insensitive comparison

      blnStrComp = CBool(UCase(strComp1) = UCase(strComp2))

  End Select 'blnCase

End Function 'blnStrComp

 

 

'********************************************************************

'*

'* Function blnStrComp

'*

'*   Author: NetworkAdminKB.com

'*  Created: 2008-05-18

'* Modified: 2008-06-19

'*

'* Purpose: Returns a boolean based on the results of the strings/values

'*            being evaluated by the provided operator.  All 6 common

'*            operations are supported (=, >, <, >=, <=, <>).   Numbers will

'*            be evaluated as numbers, and are not affected by blnCase.

'*

'* Input:   strComp1  A string to compare with strComp2

'*          strOpr    A string containing the operation.

'*                      Valid Operation Strings

'*                      "=", ">", "<", ">=", "<=", "<>"

'*          strComp2  A string to compare with strComp1

'*          blnCase   A boolean indicating case sensitive comparisons.

'*                      True  = Case Sensitive comparison

'*                      False = Case Insensitive comparison (Default)

'*

'* Output:  Returns a boolean indicating the appropriate result for

'*            the comparison being performed.

'*            True  = The comparison statement was correct

'*            False = The comparison statement was incorrect

'*          Returns vbNull if the strOpr is not valid.

'*

'* Changes:

'* 2008-06-19: Complete re-write allowing the specification of the type

'*               of operation to perform.  In previous versions the equal

'*               comparison operations was assumed.

'* 2008-06-19: Tested the use of the Eval function to simplify the procedure,

'*               the results were very SLOW...do not use Eval.

'* 2008-06-19: Discovered that removing the CBool function from the results

'*               increased speed, and a boolean was still returned.

'* 2008-06-19: Added check for numeric values before converting to UCase.

'*               This will prevent numbers from being evaluated as strings

'*               when doing case insensitive comparisons.

'********************************************************************

Function blnStrComp(ByVal strComp1, ByVal strOpr, ByVal strComp2, ByVal blnCase)

  'Version 3.0 2008-06-19

 

  Select Case blnCase

    Case True

      'case sensitive comparison

      'do nothing to strComp1 and strComp2

    Case False

      'case insensitive comparison

      'UCase and LCase will convert numbers to strings, to prevent

      'this we check for number prior to converting case.

      If NOT IsNumeric(strComp1) Then strComp1 = UCase(strComp1)

      If NOT IsNumeric(strComp2) Then strComp2 = UCase(strComp2)

    Case Else

      'Default case insensitive comparison

      'UCase and LCase will convert numbers to strings, to prevent

      'this we check for number prior to converting case.

      If NOT IsNumeric(strComp1) Then strComp1 = UCase(strComp1)

      If NOT IsNumeric(strComp2) Then strComp2 = UCase(strComp2)

  End Select 'blnCase

  Select Case strOpr

    Case "="

      blnStrComp = strComp1 = strComp2

    Case ">"

      blnStrComp = strComp1 > strComp2

    Case "<"

      blnStrComp = strComp1 < strComp2

    Case ">=", "=>"

      blnStrComp = strComp1 >= strComp2

    Case "<=", "=<"

      blnStrComp = strComp1 <= strComp2

    Case "<>", "><"

      blnStrComp = strComp1 <> strComp2

    Case Else

      Wscript.Echo "blnStrComp: an incorrect operator was specified '" & _

                      strOpr & "'."

      blnStrComp = vbNull

  End Select 'strOpr

End Function 'blnStrComp

Article ID: 373, Created On: 9/25/2011, Modified: 9/25/2011