Use of LEN()

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
 
M

Marina

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.
 
C

Cowboy \(Gregory A. Beamer\) [MVP]

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!
***************************************************************
 
L

Lloyd Sheen

Since you are passing a String just do the following

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


Lloyd Sheen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top