帮帮忙吧,怎样才能使用上这段自定义函数

aeae12 2007-10-28 01:56:43
这是一段字符串匹配的函数,在ACCESS中使用没有问题,请问在vb中怎样使用它呢,请哪位好心人给说明一下,用代码调用,改造

函数都行,最好写段代码,我水平很烂的。不胜感激!!!
我用adodc连接ACCESS
ACCESS中执行语句:
SELECT * FROM CompareBase INNER JOIN Zd_WC2 ON AlikePercentEx(CompareBase.Xm_name,zd_WC2.WC_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
...全文
53 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧