如何自定义一个返回值为空的函数?

caoshiying 2009-11-11 09:42:19
我自学VB.NET,想自定义一个返回值为空的函数,不知道用哪个关键字,请说明一下。
...全文
867 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
longhair9711 2009-11-12
  • 打赏
  • 举报
回复
Private Function FunctionName

return nothing

End Function
yanlongwuhui 2009-11-12
  • 打赏
  • 举报
回复
return nothing
sizhirunhua 2009-11-12
  • 打赏
  • 举报
回复
使用过程不就行了

或者return ""
红叶哥 2009-11-12
  • 打赏
  • 举报
回复
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim O As Object
O = FunctionName()
If IsNothing(O) = True Then
MsgBox("空值")
End If
End Sub
Public Function FunctionName() As Object
Return Nothing '返回空
End Function
AManStudio 2009-11-12
  • 打赏
  • 举报
回复
Function有返回,SUB无返回值

Public Function FunctionName(Byval Sender as Object) As Object
Return Nothing '返回空
'Return DBNull.Value 'DBNull类型的空
'Return String.Empty '返回空字符
'....
'..
End Function
kuhura 2009-11-12
  • 打赏
  • 举报
回复
用过程 ,没有返回值

sub 函数名
end sub
beycheung 2009-11-12
  • 打赏
  • 举报
回复
就这样吧
[Quote=引用 8 楼 longhair9711 的回复:]
Private Function FunctionName

    return nothing

End Function
[/Quote]
清晨曦月 元老 2009-11-12
  • 打赏
  • 举报
回复
在VB.NET里面,谈到返回值,一般都是函数的(如果用一个参数来接受过程的返回值,IDE是不会接受的)。如果是过程,则需要用BYREF来返回(相当于OUT)。
而楼主所说的“空”,这个字不好理解。一般意义上来讲,应该是指什么也没有,那就当做NOTHING?也许是DBNULL?这都不好说。不过可以这样概括,所有返回值为引用的,则返回NOTHING时得到的返回值就是“空”,而如果你的返回值被定义成非引用型的,则返回NOTHING时得到的是该类型的默认值。这里较为“特殊”的是STRING类型,它是引用型。
可以测试以下代码
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(TypeName(test1()))
MsgBox(TypeName(test2()))
MsgBox(TypeName(test3()))
MsgBox(TypeName(test4()))
End Sub

Function test1() As Object
Return Nothing
End Function

Function test2() As Object
Return DBNull.Value
End Function

Function test3() As String
Return Nothing
End Function

Function test4() As Integer
Return Nothing
End Function
gui0605 2009-11-11
  • 打赏
  • 举报
回复
VB中应该是return nothing吧?
wuyq11 2009-11-11
  • 打赏
  • 举报
回复
Return 为空就是
「已注销」 2009-11-11
  • 打赏
  • 举报
回复
请举例子,说得越详细,我就采用谁的答案,并且加分。
whycom 2009-11-11
  • 打赏
  • 举报
回复
???
void
SQL77 2009-11-11
  • 打赏
  • 举报
回复
DBNULL.VALUE
?

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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