My InStr keeps telling me its mismatched

时光怂恿深爱的人放手 提交于 2019-12-24 17:18:14

问题


 englishReasonsToGoToSecondFloor = "test" & ";" & "exam & pay" & ";" & " possible fake"

So my values may contain a & or (space) or just a single word. Each item is separated by a ";"

so the final list will look like "test;exam & pay;possible fake"

When the user selects an item from the Listbox, I want to quickly compare the selection with the words in the variable

rowValue = Trim(listboxTest.Column(1))
englishResult = InStr(rowValue, englishReasonsToGoToSecondFloor, CompareMethod.Text)

I can mouse over the rowValue and I see there is a value.

I've also tried with

englishResult = InStr(rowValue, englishReasonsToGoToSecondFloor, vbTextCompare)

Error message is "Run-time error '13'


回答1:


Check the help for InStr(). Or here .

 InStr ([start, ] string1, string2 [, compare ] )

The start argument is required if compare is specified.

So leave out the compare argument, or supply start.

And you have the string arguments mixed up (I need to remind myself of the correct order pretty often too).

string1 - Required. String expression being searched.
string2 - Required. String expression sought.

So you want

englishResult = InStr(1, englishReasonsToGoToSecondFloor, rowValue, vbTextCompare)


来源:https://stackoverflow.com/questions/38353529/my-instr-keeps-telling-me-its-mismatched

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!