String =字符串比较样式(理论?)

时间:2012-12-21 19:37:05

标签: vba if-statement access-vba

我目前无法测试代码(没有笔记本电脑),但在If语句中如下所示:

Dim StrA As String, StrB As String

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

If语句是以二进制还是文本方式检查字符串?

2 个答案:

答案 0 :(得分:4)

比较通常是文本的,stra = STRA,但你可以使用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

答案 1 :(得分:2)

取决于settings option compare text最常见,我认为