Use of LEN()

  • Thread starter Thread starter Steven K
  • Start date Start date
S

Steven K

Hello,

I have the following function that I am migrating from ASP, but I am getting
the following error: Name 'Len' is not declared.

Any help with this would be appreciated.

Public Function vba_Null_Value(varNullTest As String) As String
If Len(varNullTest) = 0 Then
Return NULL
Else
Return varNullTest
End If
End Function
 
Strings have a Length property, so just check that. This is what I would use
for the function:

If IsNothing(varNullText) OrElse varNullText.Length = 0 Then
Return Nothing
Else
return varNullTest
End If

Of course this will return a VB reference of nothing, my guess is that you
were trying to return something you could use to set a database value to
NULL. A database null, and a variable referencing nothing, are completely
unrelated things in .NET. If this was the purpose of this function, you
would have to modify it to be of return type Object, and return a
DBNull.Value in case the string tested for empty.
 
LEN() is not the biggest issue here, IMO, but the way in which NULLs and
DBNulls are handled. I assume this from the function you have below.

Testing from a database, you have the ability to test against DBNull.Value

If you want to test a nothing object You can still test IS NOTHING.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************************************************
Think outside the box!
***************************************************************
 
Since you are passing a String just do the following

if varNullTest = String.Empty then
.........


Lloyd Sheen
 
Back
Top