StrComp Function

Syntax:

StrComp(Str1,Str2,Comp)

Group:

String

Description:

Compare two strings.

 

Parameter

Description

Str1

Compare this string with Str2. If this value is Null then Null is returned.

Str2

Compare this string with Str1. If this value is Null then Null is returned.

Comp

This numeric value indicates the type of comparison. See Comp table below.

  

 

Result

Description

-1

Str1 is less than Str2.

0

Str1 is equal to Str2.

1

Str1 is greater than Str2.

Null

Str1 or Str2 is Null.

 

 

Comp

Value

Effect

vbUseCompareOption

-1

Performs the comparison using the Option Compare statement value.

vbBinaryCompare

0

Compares the string's binary data.

vbTextCompare

1

Compares the string's text using the collation rules.

vbDatabaseCompare

2

Microsoft Access only. (Not supported.)

 

See Also:

LCase$( ), Option Compare, StrConv$( ), UCase$( )

 

Example:

Sub Main
  Debug.Print StrComp("F","e") ' -1
  Debug.Print StrComp("F","e",1) ' 1
  Debug.Print StrComp("F","f",1) ' 0
End
Sub