Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 检查字符串是否包含在另一个字符串中_Vba_Loops - Fatal编程技术网

Vba 检查字符串是否包含在另一个字符串中

Vba 检查字符串是否包含在另一个字符串中,vba,loops,Vba,Loops,我有一个字符串的问题,我想得到一些帮助。 通过迭代,我得到了htmlelement innertex: 2017年12月31日 31-12-2016 31-12-2015 等等 我希望在这些元素中搜索通过inputbox插入的一个字符串,但该字符串只包含年份(例如2017年)。 我尝试使用instr和instrrev,在这两种情况下,即使有字符串也不匹配 这是我代码的一部分: Dim setdata as String Dim datacheck as mshtml.ihtmlelement D

我有一个字符串的问题,我想得到一些帮助。 通过迭代,我得到了htmlelement innertex:

2017年12月31日

31-12-2016

31-12-2015 等等

我希望在这些元素中搜索通过inputbox插入的一个字符串,但该字符串只包含年份(例如2017年)。 我尝试使用instr和instrrev,在这两种情况下,即使有字符串也不匹配

这是我代码的一部分:

Dim setdata as String
Dim datacheck as mshtml.ihtmlelement
Dim datachecks as mshtml.ihtmlelementCollection

Setdata = application.inputbox 'etc.

Datachecks = iedoc.getelementbyclassname("example") 'it finds all the date in the page (I checked through debug.print)'

For each datacheck in datachecks:
If instr(setdata, datacheck.innertext, vbtextcompare) then 'i also tried instrrev'
Debug.print "ok"
Else
Debug.print "no"
End if
Next datacheck
即使通过inputbox我插入2017,并且元素集合包含2017年12月31日,我也始终得不到。
你能帮我吗?

你把顺序弄混了吗。对我来说,您的代码似乎在“setdata”中查找“datacheck”,而我的理解是您在“datacheck”中查找“setdata”


Fnk

你把顺序弄混了吗。对我来说,您的代码似乎在“setdata”中查找“datacheck”,而我的理解是您在“datacheck”中查找“setdata”


Fnk

检查您的变量名,首先是数据检查,然后是数据检查。它可能会有影响。检查变量名,首先是数据检查,然后是数据检查。它可能会产生影响。
Dim a as String         'The string to look for
Dim b as String         'The string to look in
Dim c as Long

a = "A"
b = "aabb AbAb BAAb"

c = InStr(b,a)         'Function looking for the first occurrence of a in b
Print.Debug c          'This will give the value of 6, the location "A" first appears in string b.