函数放在模块中,查询设计方便多了
Public Function GetInStrNum(StringCheck As String, StringFind As String, NumerLen As Integer) As Double
'从一段文本中取得指定字符串后面的数字
'函数调用方法:
'GetInStrNum(StringCheck,StringFind,NumerLen)
'返回值:Double值或者0
'参数:StringCheck 源字符串
' StringFind 要查找的字符串(数字之前的)
' NumerLen 要返回的数字长度,如果指定值大于找到的数字长度,只返回找到的数字
'例:MyString = "平整面积0.1120公顷,土方量163.35立方米;土地翻耕0.1089公顷;地力培肥0.1089公顷, 30立方米水窖1座。"
'则:GetInStrNum(MyString,"平整面积",8)将返回0.1120
' GetInStrNum(MyString,"土方量",3)将返回163
'注:如果一段字符串中包含多个StringFind,只返回第一个后面的数字;如果数字中含有逗号千分位,可能返回错误的值
Dim n As Integer
Dim tmpStr As String
n = InStr(1, StringCheck, StringFind)
If n = 0 Then
GetInStrNum = 0
Else
tmpStr = Mid(StringCheck, n + Len(StringFind), NumerLen)
GetInStrNum = Val(tmpStr)
End If
End Function