wisock通讯数据收到后,字答串有有数字,如何提取出来为如何变成int型
为了变成int型,我在发送前转换成字符,收到后再转换地来,可int型变成了,提放到sql中查询,又提示数据类型不对,
Dim pppp As Integer
pppp = 0
Do While Len(InString) > 0
If Left(InString, 1) = "a" Then
pppp = pppp & 0
End If
If Left(InString, 1) = "b" Then
pppp = pppp & 1
End If
If Left(InString, 1) = "c" Then
pppp = pppp & 2
End If
If Left(InString, 1) = "d" Then
pppp = pppp & 3
End If
If Left(InString, 1) = "e" Then
pppp = pppp & 4
End If
If Left(InString, 1) = "f" Then
pppp = pppp & 5
End If
If Left(InString, 1) = "g" Then
pppp = pppp & 6
End If
If Left(InString, 1) = "h" Then
pppp = pppp & 7
End If
If Left(InString, 1) = "i" Then
pppp = pppp & 8
End If
If Left(InString, 1) = "j" Then
pppp = pppp & 9
End If
InString = Right(InString, (Len(InString) - 1))
Loop
abcd = Right(pppp, (Len(pppp) - 1))
为了变成int型,我在发送前转换成字符,收到后再转换地来,可int型变成了,提放到sql中查询,又提示数据类型不对,
Dim pppp As Integer
pppp = 0
Do While Len(InString) > 0
If Left(InString, 1) = "a" Then
pppp = pppp & 0
End If
If Left(InString, 1) = "b" Then
pppp = pppp & 1
End If
If Left(InString, 1) = "c" Then
pppp = pppp & 2
End If
If Left(InString, 1) = "d" Then
pppp = pppp & 3
End If
If Left(InString, 1) = "e" Then
pppp = pppp & 4
End If
If Left(InString, 1) = "f" Then
pppp = pppp & 5
End If
If Left(InString, 1) = "g" Then
pppp = pppp & 6
End If
If Left(InString, 1) = "h" Then
pppp = pppp & 7
End If
If Left(InString, 1) = "i" Then
pppp = pppp & 8
End If
If Left(InString, 1) = "j" Then
pppp = pppp & 9
End If
InString = Right(InString, (Len(InString) - 1))
Loop
abcd = Right(pppp, (Len(pppp) - 1))
Dim rgx As Object, mat As Object
Set rgx = CreateObject("VBscript.RegExp")
s = "abcd123中国44你好567" 's假定为接收到的数据,里面含有数字
rgx.Global = True
rgx.Pattern = "\d*\d"
For Each mat In rgx.Execute(s)
Debug.Print CInt(mat.Value) '将提取出来的数字转换为int型,并显示结果
Next