无法使用InStr将Array元素与String进行比较

时间:2017-11-15 18:46:36

标签: vb6

我正在使用VB6,我正在尝试将字符串与Array元素进行比较。我知道如果字符串存在,它将始终在索引0中。目前它总是跳到End If。我做错了什么?

Dim attributeFinal As String, 
strArray() As String, 
stringFound As Integer, 
code As String

attributes = "Material=10011,C=123123"

strArray = Split(attributes, ",")
If UBound(strArray) Then
    code = strArray(0)
    stringFound = InStr(1, "Material", code)
    If stringFound <> 0 Then
        attributeFinal = code & ",C=" & cCode
    End If
End If

1 个答案:

答案 0 :(得分:0)

感谢@AndrewMorton。比较字符串的参数顺序相反。

Dim attributeFinal As String, 
strArray() As String, 
stringFound As Integer, 
code As String

attributes = "Material=10011,C=123123"

strArray = Split(attributes, ",")
If UBound(strArray) Then
    code = strArray(0)
    stringFound = InStr(code, "Material")
    If stringFound <> 0 Then
        attributeFinal = code & ",C=" & cCode
    End If
End If