在代码[VB6]中,我在集合中搜索特定数据。 Fam87来自文本文件。
Function cumplefam(Fam87FO As String, rFamn1 As String, rFamn2 As String, rFam87 As String) As Boolean
Dim objfam As Tfamilias
Dim c1, c2, c3 As String
**objfam = getfamilia(Fam87FO)**
If rFamn1 = "" Then
c1 = "OK"
Else
If InStr(objfam.cFamn1, rFamn1) > 0 Then
c1 = "OK"
Else
c1 = "NO OK"
End If
End If
If rFamn2 = "" Then
c2 = "OK"
Else
If InStr(objfam.cFamn2, rFamn2) > 0 Then
c2 = "OK"
Else
c2 = "NO OK"
End If
End If
If rFam87 = "" Then
c3 = "OK"
Else
If InStr(objfam.cFam87, rFam87) > 0 Then
c3 = "OK"
Else
c3 = "NO OK"
End If
End If
If c1 = "OK" And c2 = "OK" And c3 = "OK" Then
cumplefam = True
Else
cumplefam = False
End If
End Function
当getfamilia运行时出现问题:
Function getfamilia(cFam As String) As Tfamilias
On Error Resume Next
Set getfamilia = Nothing
getfamilia = colfamilias(cFam)
End Function
逐步运行它确实可以获得我想要的数据,但是当它点击结束函数时它会显示:
运行时错误' 91':对象变量或未设置块变量
我对VB缺乏经验,所以我不能真正理解我的错误。
答案 0 :(得分:1)
假设colfamilias
实际上已初始化,对于作为对象的返回值,您必须使用Set
:
Function getfamilia(cFam As String) As Tfamilias
On Error Resume Next
Set getfamilia = Nothing
Set getfamilia = colfamilias(cFam) '// change this line
End Function
在你对函数的调用中:
Set objfam = getfamilia(Fam87FO)