我的InStr不断告诉我它不匹配 [英] My InStr keeps telling me its mismatched

查看:71
本文介绍了我的InStr不断告诉我它不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 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)

我可以将鼠标悬停在rowValue上,然后看到有一个值.

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

我也尝试过

englishResult = InStr(rowValue, englishReasonsToGoToSecondFloor, vbTextCompare)

错误消息是运行时错误'13'

Error message is "Run-time error '13'

推荐答案

检查InStr()的帮助.或此处.

Check the help for InStr(). Or here .

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

如果指定了compare,则必须使用start参数.

The start argument is required if compare is specified.

因此省去compare参数,或提供start.

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-必需.正在搜索字符串表达式.
string2-必填.寻找字符串表达式.

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

所以你想要

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

这篇关于我的InStr不断告诉我它不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆