Check if a string contains specific characters using VBS script

懵懂的女人 提交于 2019-12-05 13:19:52

You are using InStr incorrectly. Your code:

InStr(Tableau(1,i), "average", vbTextCompare)

The signature for InStr is:

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

But the gotcha here is that it has two optional parameters, one of them being in the front, with a special condition:

Optional. Specifies the starting position for each search. The search begins at the first character position (1) by default. This parameter is required if compare is specified

So because you are using the fourth parameter with the value vbTextCompare, you need to specify the starting point in the first parameter as well, which would be 1 (first character) in your case. So, the corrected code is:

InStr(1, Tableau(1,i), "average", vbTextCompare)

The error message you see basically complains that the first parameter is expected to be an integer, but you are feeding it a string.

See InStr docs.

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