Excel VBA在拆分后给出的十进制数除以types不匹配

我有下面的代码,它需要一个string温度,这肯定有2个数字分隔“(”,然后做一些math运算对他们。我得到一个types不匹配的错误,当试图做math,尽pipe使用CDec将它们转换为十进制数字,但我该怎么做呢?谢谢。

tempArry = Split(temp, " ") tolTemp = (CDec(tempArry(LBound(tempArry)) + tempArry(LBound(tempArry) + 2))) / 2 noms(j) = tolTemp tols(j) = tolTemp - CDec(tempArry(LBound(tempArry))) 

根据你的意见,你似乎假设你可以添加两个string作为数字。

由于input( tempvariables)是一个string,所以你要添加的数组元素也是string,所以当你编写tempArry(LBound(tempArry)) + tempArry(LBound(tempArry) + 2) ,输出将是两个string的连接(这是112.34117.89 – 因此types不匹配 )。

为了解决它转换成十进制, 然后再尝试添加它们:

 tolTemp = (CDec(tempArry(LBound(tempArry))) + CDec(tempArry(LBound(tempArry) + 2))) / 2