473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Use of LEN()

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

--
Thanks in advance,

Steven
Nov 18 '05 #1
5 1946
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.

"Steven K" <sk****@troop.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
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

--
Thanks in advance,

Steven

Nov 18 '05 #2
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!
************************************************** *************
"Steven K" <sk****@troop.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
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

--
Thanks in advance,

Steven

Nov 18 '05 #3
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!
************************************************** *************
"Steven K" <sk****@troop.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
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

--
Thanks in advance,

Steven

Nov 18 '05 #4
Since you are passing a String just do the following

if varNullTest = String.Empty then
.........
Lloyd Sheen

"Steven K" <sk****@troop.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
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

--
Thanks in advance,

Steven

Nov 18 '05 #5
Since you are passing a String just do the following

if varNullTest = String.Empty then
.........
Lloyd Sheen

"Steven K" <sk****@troop.com> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
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

--
Thanks in advance,

Steven

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jeff Wagner | last post by:
Can someone please explain the following to me: >>> str1 = "here" >>> str2 = "here", "we", "are" >>> len(str1) 4 >>> len(str2) 3 Why is len(str1) = 4 and len(str2) = 3?
8
by: Roy Smith | last post by:
Is the length of a list stored in the object, or does len() have to count the elements each time you call it? In other words, is len (list) O(1) or O(n)?
11
by: PC Datasheet | last post by:
How do I get the Len function to count a space at the end of a string? For example, if I enter AB(space), how do I get Len to return 3 instead of 2? Thanks, Steve
4
by: Laphan | last post by:
Hi all In my functions I'm using a double-check all the time to trap if a value has nothing in it and my question is do I need this double-check. My check line is: IF IsNull(xxx) OR...
6
by: Thomas Girod | last post by:
Hi there. I'm trying to use new-style classes, but there is something i'm obviously missing here it is : class Data(list): __slots__ =
14
by: Tor Erik Soenvisen | last post by:
Hi, (len() is 1) == (len() == 1) =True Is this the case for all numbers? I've tried running the following: for i in range(10000): for j in range(10000): if i != j:
16
by: Thomas Guettler | last post by:
Hi, The function len() is not mentioned in the Python 3000 PEPs. I suggest that at least lists, tupples, sets, dictionaries and strings get a len() method. I think the len function can stay,...
23
by: anon.asdf | last post by:
Hello! In the following code-snippet, is it possible to initialize each element of arr, with STRUCT_INIT? struct mystruct { int a; char b; };
15
by: Michael B Allen | last post by:
I like to use limit pointers as sentinels when working on buffers of data. Meaning I use ptr < lim where ptr and lim are both pointers rather than n 0 to determine if it is safe to proceed writing...
10
by: Nikhil | last post by:
which one is better? and why? __len__() is a built-in function of the list object and is updated along with the list object elements and will be useful incase the list is very huge. len() is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.