Ask a Question related to ASP Database, Design and Development.
-
Mike #1
error in aspfaq #2304??
This is referring to aspfaq #2304...
I've got a column of data that sometimes is null, sometimes is 0, and
sometimes is some other number. I'm filling out a table with it and I
don't want the 0's to show, so I wrote this function to get rid of
them. I looked on aspfaq.com why my simple replace(column, "0", "")
didn't work, and sure enough I found an answer :) However, when I
tried the recommendation it didn't work...
If I do this (basically 2304):
function ReplaceZeros(column)
if len(column) = 0 then
column = ""
else
column = replace(column, "0", "")
end if
ReplaceZeros = column
end function
I get this:
Microsoft VBScript runtime (0x800A005E)
Invalid use of Null: 'Replace'
/tradelist_3.asp, line 100
If I change the code to this it works fine:
function ReplaceZeros(column)
if isNull(column) then
column = ""
else
column = replace(column, "0", "")
end if
ReplaceZeros = column
end function
-Mike
Mike Guest
-
Yes, aspfaq.com is down.
Working on it. No ETA yet, sorry. -
Is ASPFAQ down?!
Just kidding. Today is Aaron's birthday and this is a surprise. So when he gets here, everyone yell "Happy Birthday!" Ok, turn out the lights, I... -
ASP.NET on ASPFAQ.com?
I am sure you have several ... but what articles on aspfaq.com do you have that talk about starting ASP.NET ... I have it available on my webhost,... -
About www.aspfaq.com
Message from Aaron about www.aspfaq.com issues: I'm in the midst of switching database hosts, but I'm on vacation (out of the country) until... -
corrupted records with 椀氀 or d夊ĀĀĀऀ
Hi there, we have a database of around 600 records, 4 tables are linked to 1 main form, however when scrolling through members or adding new... -
Bob #2
Re: error in aspfaq #2304??
Mike wrote:
The length of Null (which really means "unknown") will always evaluate to
Null ("unknown"). You cannot know the length of an unknown piece of data.
Since it evaluates to Null, and Null is not equal to 0, this logic fails.
You could reverse the logic of this to:
If len(column) > 0 then
column = replace(column, "0", "")
else
column = ""
end if
or use IsNull as you did. The only problem with using IsNull is if you need
to react to both a Null value and an empty string. Using IsNull would
require this:
If IsNull(somevariable) then
...
elseif somevariable = "" then
... 'this may be the same code as above
else
...
end if
Using "if len(somevariable)> 0 then" results in more concise code.
Bob Barrows
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Bob Guest
-
Aaron #3
Re: error in aspfaq #2304??
> if len(column) = 0 then
I had the logic reversed in the article. (Though I believe it worked in
some previous version of VBScript, because I test all code samples before I
post them.)
To illustrate why you can use len>0 to determine not null, but you can't use
len=0 to determine null,
<%
w = "foo"
x = NULL
y = ""
' no z
response.write "Len(w): " & len(w) & "<br>"
response.write "Len(x): " & len(x) & "<br>"
response.write "Len(y): " & len(y) & "<br>"
response.write "Len(z): " & len(z) & "<p>"
lenwg0 = false: lenxg0 = false: lenyg0 = false: lenzg0 = false
if len(w) > 0 then lenwg0 = true
if len(x) > 0 then lenxg0 = true
if len(y) > 0 then lenyg0 = true
if len(z) > 0 then lenzg0 = true
response.write "Len(w) > 0: " & lenwg0 & "<br>"
response.write "Len(x) > 0: " & lenxg0 & "<br>"
response.write "Len(y) > 0: " & lenyg0 & "<br>"
response.write "Len(z) > 0: " & lenzg0 & "<br>"
%>
--
http://www.aspfaq.com/
(Reverse address to reply.)
Aaron Guest



Reply With Quote

