点击下载此附件
'功能:从字符串中取出夹杂的数字
'方法一
'使用方法:GetNum([字段名称])
Function GetNum(Exp As String) As Double
Dim lntI As Long
Dim strWord As String
For lntI = 1 To Len(Exp)
strWord = Mid(Exp, lntI, 1)
If strWord Like "[0-9]" Then
GetNum = GetNum & strWord
End If
Next
End Function
'方法二
Function GetNum2(Exp As String) As Double
Dim lntI As Long
Dim strWord As String
For lntI = 1 To Len(Exp)
strWord = Mid(Exp, lntI, 1)
If IsNumeric(strWord) Then
GetNum2 = GetNum2 & strWord
End If
Next
End Function
方法三
Private Sub cmdok_Click()
Dim Str
Set re = CreateObject("VBScript.RegExp")
re.Global = True
re.IgnoreCase = True
Str = Me.txttest
re.Pattern = "\d{1,}"
Set Matches = re.Execute(Str)
For Each Match In Matches
MsgBox Match.Value
Next
End Sub