vb调用自定义函数 悬赏现金100元

aeae12 2007-10-28 09:58:58
我在vb中用adodc连接ACCESS,下面这段函数是字符串匹配函数,语句和函数在ACCESS中测试没有问题,在程序中怎样作才能让这段函数起作用呢,哪位好心人帮帮忙给段代码,修改语句,使用函数都行,谢谢!测试通过小弟愿支付现金100元,具体事宜可回帖中商量,我的QQ41326168


执行语句:
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 ADODB.Recordset

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

Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strconnection As String

Dim V_Str As String
Set con = New ADODB.Connection
Set rs = New ADODB.Record
On Error GoTo AlikePercentEx
cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\接口对应程序\Interface.mdb;Persist Security Info=False"



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
...全文
50 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
changechange 2008-09-27
  • 打赏
  • 举报
回复
语句和函数在ACCESS中测试没有问题,在程序中怎样作才能让这段函数起作用呢----------直接用不就得了
OracleRoob 2007-10-30
  • 打赏
  • 举报
回复
Access使用的是VBA,与VB还是有些差异的,建议去VB开发版问问。

7,731

社区成员

发帖
与我相关
我的任务
社区描述
Microsoft Office Access是由微软发布的关系数据库管理系统。它结合了 MicrosoftJet Database Engine 和 图形用户界面两项特点。
社区管理员
  • Access
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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