+ -
当前位置:首页 → 问答吧 → 如何将null做为参数传递给自定义函数

如何将null做为参数传递给自定义函数

时间:2011-12-14

来源:互联网

Public Function yesToOne(stra As String)
  If IsNull(stra) Then
  yesToOne = 0
  Else
  If stra = "是" Then
  yesToOne = 1
  Else
  yesToOne = 0
  End If
  End If
End Function

如果传入的参数为空,就会出错.这个怎么改?谢谢.

作者: kkabc99   发布时间: 2011-12-14

VB code
Public Function yesToOne(stra As String)
  If trim(stra)="" Then
      yesToOne = 0
  Else
      If stra = "" Then
          yesToOne = 1
      Else
          yesToOne = 0
      End If
  End If
End Function

作者: Leftie   发布时间: 2011-12-14

引用 1 楼 leftie 的回复:
VB code

Public Function yesToOne(stra As String)
If trim(stra)="" Then
yesToOne = 0
Else
If stra = "是" Then
yesToOne = 1
Else
yesToOne = 0
En……

这招不灵. 我是把 as string 去掉就可以了,但应该有更好的方法吧?

作者: kkabc99   发布时间: 2011-12-14

Public Function yesToOne(stra As variant)
  If IsNull(stra) Then
  yesToOne = 0
  Else
  If stra = "是" Then
  yesToOne = 1
  Else
  yesToOne = 0
  End If
  End If
End Function

作者: worldy   发布时间: 2011-12-14