我用TDBGrid显示,如果两个文本型字段中的名称相似度在50%-100%显示在一起,请问如果不在Access中建立查询,该怎么写SQL又怎样写函数,相似度的限定最好在程序中能设置,请哪位大哥费心费事给写段代码。我这有段相似度要求很低的匹配函数测试没问题,不知能不能改一改,我真的很需要这段代码,请好心人帮忙,不胜感激!!!SELECT * FROM CompareBase INNER JOIN Zd_yp5 ON AlikePercentEx(CompareBase.Xm_name,zd_yp5.yp_name);
Public Function AlikePercentEx(ByVal strTextSrc As String, _
ByVal strTextDest As String, _
Optional ByVal blnCaseSensitive As Boolean = False, _
Optional ByVal blnExactPositionMatch As Boolean = False) As Double
Dim o_strTextSrc As String
Dim o_strTextDest As String
Dim o_strTextLonger As String
Dim o_strTextShorter As String
Dim o_strByteSrc As String
Dim o_strByteDest As String
Dim o_lngLength As Long
Dim o_lngItems As Long
Dim o_lngMatches As Long
Dim o_lngStart As Long
If Not blnCaseSensitive Then
o_strTextSrc = UCase(strTextSrc)
o_strTextDest = UCase(strTextDest)
Else
End If
If o_strTextSrc = o_strTextDest Then '如果一致
AlikePercentEx = 100#
Else
If Len(o_strTextSrc) = Len(o_strTextDest) Then
o_strTextLonger = o_strTextSrc
o_strTextShorter = o_strTextDest
ElseIf Len(o_strTextSrc) > Len(o_strTextDest) Then
o_strTextLonger = o_strTextSrc
o_strTextShorter = o_strTextDest
Else
o_strTextLonger = o_strTextDest
o_strTextShorter = o_strTextSrc
End If
o_lngLength = Len(o_strTextShorter)
o_lngStart = InStr(o_strTextLonger, Left(o_strTextShorter, 1))
If o_lngStart Then
o_lngMatches = 1
For o_lngItems = o_lngStart + 1 To Len(o_strTextLonger)
If blnExactPositionMatch Then '位置必须一致
o_strByteSrc = Mid(o_strTextLonger, o_lngItems, 1)
o_strByteDest = Mid(o_strTextShorter, o_lngItems - o_lngStart + 1, 1)
If o_strByteSrc = o_strByteDest Then
o_lngMatches = o_lngMatches + 1
Else
End If
Else '任意位置模糊匹配
End If
Next
AlikePercentEx = (o_lngMatches / o_lngLength) * 100 \ 1
Else
AlikePercentEx = 0#
End If
End If
End Function
Public Function AlikePercentEx(ByVal strTextSrc As String, _
ByVal strTextDest As String, _
Optional ByVal blnCaseSensitive As Boolean = False, _
Optional ByVal blnExactPositionMatch As Boolean = False) As Double
Dim o_strTextSrc As String
Dim o_strTextDest As String
Dim o_strTextLonger As String
Dim o_strTextShorter As String
Dim o_strByteSrc As String
Dim o_strByteDest As String
Dim o_lngLength As Long
Dim o_lngItems As Long
Dim o_lngMatches As Long
Dim o_lngStart As Long
If Not blnCaseSensitive Then
o_strTextSrc = UCase(strTextSrc)
o_strTextDest = UCase(strTextDest)
Else
End If
If o_strTextSrc = o_strTextDest Then '如果一致
AlikePercentEx = 100#
Else
If Len(o_strTextSrc) = Len(o_strTextDest) Then
o_strTextLonger = o_strTextSrc
o_strTextShorter = o_strTextDest
ElseIf Len(o_strTextSrc) > Len(o_strTextDest) Then
o_strTextLonger = o_strTextSrc
o_strTextShorter = o_strTextDest
Else
o_strTextLonger = o_strTextDest
o_strTextShorter = o_strTextSrc
End If
o_lngLength = Len(o_strTextShorter)
o_lngStart = InStr(o_strTextLonger, Left(o_strTextShorter, 1))
If o_lngStart Then
o_lngMatches = 1
For o_lngItems = o_lngStart + 1 To Len(o_strTextLonger)
If blnExactPositionMatch Then '位置必须一致
o_strByteSrc = Mid(o_strTextLonger, o_lngItems, 1)
o_strByteDest = Mid(o_strTextShorter, o_lngItems - o_lngStart + 1, 1)
If o_strByteSrc = o_strByteDest Then
o_lngMatches = o_lngMatches + 1
Else
End If
Else '任意位置模糊匹配
End If
Next
AlikePercentEx = (o_lngMatches / o_lngLength) * 100 \ 1
Else
AlikePercentEx = 0#
End If
End If
End Function
解决方案 »
- 求动态库的调用
- 亲爱的大虾们!教教我如何隐藏按钮控件的焦点框
- 100分求,怎么用WebBrowser来提交Cookie?
- 问一个很郁闷的问题,请懂vc的vb高手解答
- 怎样判断datagrid控件中整行得到焦点和失去焦点?
- VB如何实现报表自定义打印功能?
- 我写了一个程序,是用的ACCESS2000数据库,我想改成SQL SERVER的数据库,方便吗?
- 关于屏蔽windows2000/nt的Alt+ctrl+delete 和alt+tab 键谢谢!
- 程序打包后安装时提示:找不到vb6chs
- !!!!以分欢迎吴文智,同时送两个链接,不可不看!!千万不要错过!!!!!
- MSHflexgrid控件的数据源如何改变
- vb 二进制数转十进制
你只能返回记录集后在程序中处理