473,326 Members | 2,010 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,326 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 1944
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.