VB / VBA StrComp or =

What, if anything, is the advantage of using

If StrComp(strVal1, strVal2, vbTextCompare) = 0 Then 

as opposed to using

 If strVal1 = strVal2 Then 

If Option Compare Text is set at module level, is there a difference?

I know that StrComp processes null scripts and <> scripts, I am only interested in the situation where strVal1 and strVal2 have non-zero valid strings.

+7
excel-vba string-comparison
source share
2 answers

If Option Compare Text set at module level, is there a difference?

Not. It simply offers finer control (no obligation at module level). However, if you can make such a commitment, go to the x = y option: less code is always better than code.

+1
source share

Since StrComp compares the string (with culture information), UpperCase and LowerCase do not care ... (so Hello is the same as a greeting). In the case of =, they will be different (for example, using binary comparison). If the text comparison option is at the module level, there will be no difference (but you should use StrComp if the other guy removes it) ...

+2
source share

All Articles