(此帖在另外一页给分)为什么已定义的数组在使用时会出现错误提示:未将对象引用设置到对象的实例?
'把 strNum1() 与 strNum2() 两个字符串数组相连
Public Function strANDstr(ByVal strNum1() As String, ByVal strNum2() As String) As String()
Dim arrlist As New ArrayList
Dim ANDstr() As String
Dim i As Integer
If strNum1 Is Nothing And strNum2 Is Nothing Then
Exit Function
Else
If strNum1 Is Nothing Then
Return strNum2
Exit Function
ElseIf strNum2 Is Nothing Then
Return strNum1
Exit Function
Else
For i = 0 To UBound(strNum1)
arrlist.Add(strNum1(i))
Next
For i = 0 To UBound(strNum2)
arrlist.Add(strNum2(i))
Next
-----------------------------------------------------------------------------------
ReDim ANDstr(arrlist.Count - 1)
'如果把这行注释掉,就会出现错误提示
'在命令窗口中提示《引用的“ANDstr”的值为“Nothing”。》
------------------------------------------------------------------------------------
For i = 0 To arrlist.Count - 1
ANDstr(i) = arrlist(i).ToString
Next
End If
End If
Return ANDstr
End Function
问题点数:0、回复次数:4Top
1 楼earlsen(earlsen)回复于 2004-11-04 19:40:17 得分 0
未将对象实例化Top
2 楼yoyo83(死了的尘埃)回复于 2004-11-04 21:05:39 得分 0
就使用之前没有赋值Top
3 楼fxfeixue(小虾米)回复于 2004-11-05 09:18:28 得分 0
为什么下面的代码可以执行?
'得到 dirChild 指定目录中指定类型的所有文件(文件类型为可选参数)
Public Function getChildFile(ByVal dirChild As String, Optional ByVal fileClass As String = "*.*") As String()
Dim Dir As Directory
Dim fileNum() As String
fileNum = Dir.GetFiles(dirChild, fileClass)
If fileNum Is Nothing Then
Exit Function
Else
Return fileNum
End If
End Function
是不是因为在引用 fileNum 时没有指定数组内元素位置,而在引用 ANDstr 数组时指定了元素位置?Top
4 楼fxfeixue(小虾米)回复于 2004-11-08 14:40:45 得分 0
请回答此问题的朋友到下面的地址领分:
http://community.csdn.net/Expert/topic/3521/3521928.xml?temp=.515423
如连接错误请查找标题为:“以下代码为查找指定目录下的指定文件类型的所有文件,有问题,感觉是逻辑错误,特来求教。”的帖子。
哈哈,不好意思,让大家绕来绕去的,只是上个帖子未结,还挂着50分,又舍不得,所以就烦劳各位多跑跑。Top




