避免Nothing 的函式──DisNull

引入: 自定義

 

Null 和Nothing 在Visual Basic 中都是指空,空很容易造成程式執行階段錯誤,因此時常要在函式開頭先判斷參數是否為空,實在麻煩。

 

DisNull 的原理很簡單,給予參數DisNull(主要對象, 錯誤回傳),如果主要對象為空,就傳回錯誤回傳,否則傳回主要對象。

]Function DisNull(ByVal Target As Object, ByVal ErrorReturn As Object) As Object

]If (Target Is Nothing) Then

]Return ErrorReturn

]End If

]Return Target

]End Function

文章標籤
全站熱搜
創作者介紹
創作者 GPhettoH 的頭像
GPhettoH

歇息,等待明日的天空

GPhettoH 發表在 痞客邦 留言(0) 人氣(4)