String = String comparison style (theory?)

2019-07-17 01:19发布

问题:

I can't test the code out at the moment (no laptop), but in a If statement as below:

Dim StrA As String, StrB As String

IF StrA = StrB Then
   'code for true result
Else
   'code for false result
End If

Does the Ifstatement check the strings in a binary or textual manner?

回答1:

The comparison is usually textual, stra=STRA, but you can use StrComp:

 StrComp("stra","STRA",vbbinarycompare)

http://office.microsoft.com/en-ie/access-help/strcomp-function-HA001228914.aspx

Sub IsIt()
'Option Compare Database (default): True
'Option Compare Text : True
'Option Compare Binary : False
If "stra" = "STRA" Then
    Debug.Print True
Else
    Debug.Print False
End If
End Sub


回答2:

depends on settings option compare text is most common, I think