vb中调用自定义函数

cainiao1212 2007-10-28 09:32:19
我在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 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
...全文
943 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tiger_Zhao 2007-10-30
  • 打赏
  • 举报
回复
无法解释了。
请温习软件基础知识:程序、封装、函数的作用域和可见性。
laozheng7355 2007-10-30
  • 打赏
  • 举报
回复
统一到相同的宏下面就好了吧
cainiao1212 2007-10-29
  • 打赏
  • 举报
回复
请问老鸟:按你说的VB中还有调用声明这段函数吗,宏模块中的函数程序中的SQL中能直接调用吗
cainiao1212 2007-10-29
  • 打赏
  • 举报
回复
tianhuo_soft:

执行语句后提示:连接无法执行此操作

能不能再说祥细一点,在VB中怎样最终显示在tdbgrid或dbgrid上。
bluefox1979 2007-10-29
  • 打赏
  • 举报
回复
哈哈
我也不会,顺便学学
guyehanxinlei 2007-10-29
  • 打赏
  • 举报
回复
长见识了
Tiger_Zhao 2007-10-29
  • 打赏
  • 举报
回复
要在 SQL 中调用的函数必须在 Access 的宏模块中,函数 AlikePercentEx 依旧保留在 Access 中,不能移植到 VB6 中。
cainiao1212 2007-10-29
  • 打赏
  • 举报
回复
老鸟大哥,我在ACCESS模块中定义的函数,在VB中怎么没法调用啊
tianhuo_soft 2007-10-29
  • 打赏
  • 举报
回复
dim cmd as new adodb.command
cmd.Execute "SELECT * FROM CompareBase INNER JOIN Zd_WC2 ON AlikePercentEx(CompareBase.Xm_name,zd_WC2.WC_name)
"
Tiger_Zhao 2007-10-29
  • 打赏
  • 举报
回复
与 VB 无关,Access 中 SQL 的自定义函数就是通过宏模块定义的。

7,763

社区成员

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

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