并非所有路径都返回一个值 [英] not all paths return a value
问题描述
我继承了以下迁移的vb6代码(vb2005)
但是我不知道并非所有路径返回值 squiggly - 这是一个错误goto的
''功能'吗?
私有函数CreateFolder(ByVal sFileName As String)As Boolean
错误GoTo错误
''必要时创建
如果Directory.Exists(sFileName)= False那么
Directory.CreateDirectory(sFileName)
结束如果
''创建文件夹成功
CreateFolder =真
错误:
结束功能
i have inherited the following migrated vb6 code (vb2005)
but i DONT get the "not all paths return a value" squiggly - is this a
''feature'' of on error goto?
Private Function CreateFolder(ByVal sFileName As String) As Boolean
On Error GoTo Errors
''Create it if necessary
If Directory.Exists(sFileName) = False Then
Directory.CreateDirectory(sFileName)
End If
''Succeeded in creating a folder
CreateFolder = True
Errors:
End Function
推荐答案
建议用经过结构化的异常处理替换经典的VB6错误处理
。
但是要回答你的具体问题:在代码中,(空)错误处理程序中没有返回特定值
。
只需输入CreateFolder = False即可。在错误:之后的行标签。
注意:你也可以写Return< value>而不是
"< function name> =< value>"。
/ Joergen Bech
On Tue,2006年1月3日08:30:06 -0800,guy < gu*@discussions.microsoft.com>
写道:
It is recommended that classic VB6 error handling be replaced
with structured exception handling.
But to answer your specific question: In the code, no specific value
is returned in the (empty) error handler.
Just put a "CreateFolder = False" line after the "Errors:" label.
Note: You can also write "Return <value>" instead of
"<function name> = <value>".
/Joergen Bech
On Tue, 3 Jan 2006 08:30:06 -0800, guy <gu*@discussions.microsoft.com>
wrote:
我继承了以下迁移的vb6代码(vb2005)
但是我不要得到并非所有路径都返回一个值。 squiggly - 这是错误goto的一个
''功能'吗?
私函数CreateFolder(ByVal sFileName As String)As Boolean
错误GoTo错误
''如有必要,创建它
如果Directory.Exists(sFileName)= False那么
Directory.CreateDirectory(sFileName)
结束如果
''成功创建文件夹
CreateFolder = True
错误:
结束功能
i have inherited the following migrated vb6 code (vb2005)
but i DONT get the "not all paths return a value" squiggly - is this a
''feature'' of on error goto?
Private Function CreateFolder(ByVal sFileName As String) As Boolean
On Error GoTo Errors
''Create it if necessary
If Directory.Exists(sFileName) = False Then
Directory.CreateDirectory(sFileName)
End If
''Succeeded in creating a folder
CreateFolder = True
Errors:
End Function
我没有在VB.NET中编程 - 但并非所有路径都返回一个值,因为在设置createFolder = True之前将
置为错误将无法提供返回
值,你需要返回一个bool。
在你的错误部分放置CreateFolder = False。更好 - 开始使用
try / catch语句并摆脱goto
-
问候
John Timney
Microsoft MVP
" guy" < gu*@discussions.microsoft.com>在消息中写道
news:5E ********************************** @ microsof t.com ...
I dont program in VB.NET - but not all paths return a value because falling
into error before you set createFolder=True would fail to provide a return
value, and you need to return a bool.
Put CreateFolder = False in your error section. Better still - start using
try/catch statements and get rid of the goto
--
Regards
John Timney
Microsoft MVP
"guy" <gu*@discussions.microsoft.com> wrote in message
news:5E**********************************@microsof t.com...
我继承了以下迁移的vb6代码(vb2005)
但我不知道并非所有路径都返回一个值。 squiggly - 这是错误goto的一个
''功能'吗?
私函数CreateFolder(ByVal sFileName As String)As Boolean
错误GoTo错误
''如有必要,创建它
如果Directory.Exists(sFileName)= False那么
Directory.CreateDirectory(sFileName)
结束如果
''成功创建文件夹
CreateFolder = True
错误:
结束功能
i have inherited the following migrated vb6 code (vb2005)
but i DONT get the "not all paths return a value" squiggly - is this a
''feature'' of on error goto?
Private Function CreateFolder(ByVal sFileName As String) As Boolean
On Error GoTo Errors
''Create it if necessary
If Directory.Exists(sFileName) = False Then
Directory.CreateDirectory(sFileName)
End If
''Succeeded in creating a folder
CreateFolder = True
Errors:
End Function
John Timney(MVP)写道:
John Timney ( MVP ) wrote:
我不用VB.NET编程 - 但并非所有路径都返回一个值,因为
在设置之前会出错createFolder = True将无法提供返回值,你需要返回一个bool。
I dont program in VB.NET - but not all paths return a value because
falling into error before you set createFolder=True would fail to
provide a return value, and you need to return a bool.
我肯定他意识到这个问题至于为什么他*没有*得到一个
编译器警告。我原本预计会有一个。
-
(O)enone
I''m sure he realises that, the question was as to why he *didn''t* get a
compiler warning. I would have expected there to be one too.
--
(O)enone
这篇关于并非所有路径都返回一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!