VB编程之End Function
出错的程序如下:SubFindfile(getPathAsString)DimmypathAsStringDimmynameAsStringDimmydirectory(...
出错的程序如下:
Sub Findfile(getPath As String)
Dim mypath As String
Dim myname As String
Dim mydirectory() As String
Dim i, intresult As Integer
mypath = getPath
If mypath = "" Then End Function
intresult = 2
ReDim mydirectory(intresult)
mydirectory(1) = mypath
i = 1
Do Until mydirectory(i) = ""
mypath = mydirectory(i)
If Right(mypath, 1) <> "\" Then mypath = mypath & "\"
myname = Dir(mypath, vbDirectory)
Do While myname <> ""
If myname <> "." And myname <> ".." Then
If (GetAttr(mypath & myname) And vbDirectory) = vbDirectory Then mydirectory(intresult) = mypath & myname
intresult = intresult + 1
ReDim Preserve mydirectory(intresult)
Else
List1.AddItem mypath & myname
End If
End If
myname = Dir
Loop
i = i + 1
Loop
End Sub
编译时总是提示“expected end sub”,而将“end function”改为“end sub”后,却又提示“Syntax error”............
请教各位VB编程高手:应该怎样修改这段程序啊?先谢谢大家了! 展开
Sub Findfile(getPath As String)
Dim mypath As String
Dim myname As String
Dim mydirectory() As String
Dim i, intresult As Integer
mypath = getPath
If mypath = "" Then End Function
intresult = 2
ReDim mydirectory(intresult)
mydirectory(1) = mypath
i = 1
Do Until mydirectory(i) = ""
mypath = mydirectory(i)
If Right(mypath, 1) <> "\" Then mypath = mypath & "\"
myname = Dir(mypath, vbDirectory)
Do While myname <> ""
If myname <> "." And myname <> ".." Then
If (GetAttr(mypath & myname) And vbDirectory) = vbDirectory Then mydirectory(intresult) = mypath & myname
intresult = intresult + 1
ReDim Preserve mydirectory(intresult)
Else
List1.AddItem mypath & myname
End If
End If
myname = Dir
Loop
i = i + 1
Loop
End Sub
编译时总是提示“expected end sub”,而将“end function”改为“end sub”后,却又提示“Syntax error”............
请教各位VB编程高手:应该怎样修改这段程序啊?先谢谢大家了! 展开
5个回答
展开全部
If mypath = "" Then End Function
改为
If mypath = "" Then Exit Function
最后在End Function 前加一个return语句就可以了
改为
If mypath = "" Then Exit Function
最后在End Function 前加一个return语句就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Sub Findfile(getPath As String)
Dim mypath As String
Dim myname As String
Dim mydirectory() As String
Dim i, intresult As Integer
mypath = getPath
If mypath = "" Then End Sub
intresult = 2
ReDim mydirectory(intresult)
mydirectory(1) = mypath
i = 1
Do Until mydirectory(i) = ""
mypath = mydirectory(i)
If Right(mypath, 1) <> "\" Then mypath = mypath & "\"
myname = Dir(mypath, vbDirectory)
Do While myname <> ""
If myname <> "." And myname <> ".." Then
If (GetAttr(mypath & myname) And vbDirectory) = vbDirectory Then mydirectory(intresult) = mypath & myname
intresult = intresult + 1
ReDim Preserve mydirectory(intresult)
Else
List1.AddItem mypath & myname
End If
myname = Dir
Loop
i = i + 1
Loop
End Sub
Dim mypath As String
Dim myname As String
Dim mydirectory() As String
Dim i, intresult As Integer
mypath = getPath
If mypath = "" Then End Sub
intresult = 2
ReDim mydirectory(intresult)
mydirectory(1) = mypath
i = 1
Do Until mydirectory(i) = ""
mypath = mydirectory(i)
If Right(mypath, 1) <> "\" Then mypath = mypath & "\"
myname = Dir(mypath, vbDirectory)
Do While myname <> ""
If myname <> "." And myname <> ".." Then
If (GetAttr(mypath & myname) And vbDirectory) = vbDirectory Then mydirectory(intresult) = mypath & myname
intresult = intresult + 1
ReDim Preserve mydirectory(intresult)
Else
List1.AddItem mypath & myname
End If
myname = Dir
Loop
i = i + 1
Loop
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Do Until mydirectory(i) = ""
这一句有问题,until 好像应该出现在Loop 后面。
If mypath = "" Then End Function
改为
If mypath = "" Then Exit Sub
这一句有问题,until 好像应该出现在Loop 后面。
If mypath = "" Then End Function
改为
If mypath = "" Then Exit Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1.将
If mypath = "" Then End Function
改为
If mypath = "" Then Exit Sub
2.去掉两个 End If 中的一个(在 myname = Dir 的上面)
If mypath = "" Then End Function
改为
If mypath = "" Then Exit Sub
2.去掉两个 End If 中的一个(在 myname = Dir 的上面)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
最好不要将这段代码定义为独立过程,直接写在事件里比较好处理
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询