473,402 Members | 2,064 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,402 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 1947
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.