468,512 Members | 1,476 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

problem with conditional response.write

Hi there

I need to be able to print on screen when I check if a value within a db

<td>
<% if ((Recordset1.Fields.Item("profile1").Value) <>
"") then response.Write"Pro1<br>" &
Recordset1.Fields.Item("profile1").Value%>

</td>

I am checking if profile1 contains any text if not don't print anything. If
yes then print the heading and the contents .
Now the problem is that I cannot seem to check the value and print the same
value.
If I check profile2 instead of profile1 (which contains a value) then
profile1 is printed.
At the moment only Pro1 is written to the screen but the contents of
profile1 is not, eventhough profile1 is not empty.

What could be wrong ??

Thanks
Mar 20 '06 #1
17 1595
For now I would start by writing :
Response.Write Recordset1.Fields.Item("Profile1").value=""
to make sure this is not an empty string.

If not it could be null or a string that contains white spaces (especially
if the DB field uses CHAR instead of VARCHAR)...

--
Patrice

"raj chahal" <in**@digitise.info> a écrit dans le message de news:
%2****************@TK2MSFTNGP14.phx.gbl...
Hi there

I need to be able to print on screen when I check if a value within a db

<td>
<% if ((Recordset1.Fields.Item("profile1").Value) <>
"") then response.Write"Pro1<br>" &
Recordset1.Fields.Item("profile1").Value%>

</td>

I am checking if profile1 contains any text if not don't print anything.
If
yes then print the heading and the contents .
Now the problem is that I cannot seem to check the value and print the
same
value.
If I check profile2 instead of profile1 (which contains a value) then
profile1 is printed.
At the moment only Pro1 is written to the screen but the contents of
profile1 is not, eventhough profile1 is not empty.

What could be wrong ??

Thanks

Mar 20 '06 #2
Hi there are no emty strings..
Also the text 'Pro1' is written to screen meaning that part of it executes
but not the Recordset1.Fields.Item("profile1").Value bit in its current
surroundings..

"raj chahal" <in**@digitise.info> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi there

I need to be able to print on screen when I check if a value within a db

<td>
<% if ((Recordset1.Fields.Item("profile1").Value) <>
"") then response.Write"Pro1<br>" &
Recordset1.Fields.Item("profile1").Value%>

</td>

I am checking if profile1 contains any text if not don't print anything. If yes then print the heading and the contents .
Now the problem is that I cannot seem to check the value and print the same value.
If I check profile2 instead of profile1 (which contains a value) then
profile1 is printed.
At the moment only Pro1 is written to the screen but the contents of
profile1 is not, eventhough profile1 is not empty.

What could be wrong ??

Thanks

Mar 20 '06 #3
Not sure if this is a response to my suggestion.

What I meant is that if profile1 holds " " it will print Pro1 (as this
is not "") but you won't see anything visible. Similarly if the value is
null and if I remember well my ASP days, it will print Pro1 (as this is not
"") but you won't see anything either.

I would really double check. If it still fails print those values and report
them to us :
Value<>"" ' It would definitely allows to find out if the value
is an empty string or not
IsNull(Value) ' It would allow to find is this is NULL
Len(Value) ' It would allow to find if it contains non visible
characters

--
Patrice

"raj chahal" <in**@digitise.info> a écrit dans le message de news:
%2******************@TK2MSFTNGP12.phx.gbl...
Hi there are no emty strings..
Also the text 'Pro1' is written to screen meaning that part of it executes
but not the Recordset1.Fields.Item("profile1").Value bit in its current
surroundings..

"raj chahal" <in**@digitise.info> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi there

I need to be able to print on screen when I check if a value within a db

<td>
<% if ((Recordset1.Fields.Item("profile1").Value)
<>
"") then response.Write"Pro1<br>" &
Recordset1.Fields.Item("profile1").Value%>

</td>

I am checking if profile1 contains any text if not don't print anything.

If
yes then print the heading and the contents .
Now the problem is that I cannot seem to check the value and print the

same
value.
If I check profile2 instead of profile1 (which contains a value) then
profile1 is printed.
At the moment only Pro1 is written to the screen but the contents of
profile1 is not, eventhough profile1 is not empty.

What could be wrong ??

Thanks


Mar 20 '06 #4
Perhaps you have a NULL value. Try this.

<%
'''append an empty string to deal with possibility of null value
Dim sPro1
sPro1 = Recordset1.Fields.Item("profile1").Value & ""
If sPro1 <> "" Then Response.Write "Pro1<br>" & sPro1
%>

Ray at work
"raj chahal" <in**@digitise.info> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi there

I need to be able to print on screen when I check if a value within a db

<td>
<% if ((Recordset1.Fields.Item("profile1").Value) <>
"") then response.Write"Pro1<br>" &
Recordset1.Fields.Item("profile1").Value%>

</td>

I am checking if profile1 contains any text if not don't print anything.
If
yes then print the heading and the contents .
Now the problem is that I cannot seem to check the value and print the
same
value.
If I check profile2 instead of profile1 (which contains a value) then
profile1 is printed.
At the moment only Pro1 is written to the screen but the contents of
profile1 is not, eventhough profile1 is not empty.

What could be wrong ??

Thanks

Mar 20 '06 #5
Just in case you are unframiliar with NULL....

a Null value in a data field can appear as an empty string ("")....but it is
NOT an empty string. It is a value and it behaves like a value.

So, if a field contains a NULL value, then it may appear as though it is
empty, but technically, it is not empty. Perhaps you just want to add to
your conditional test:

if ( (..... <> "") AND (..... <> "Null") ) then .....

Just a thought.

"raj chahal" wrote:
Hi there are no emty strings..
Also the text 'Pro1' is written to screen meaning that part of it executes
but not the Recordset1.Fields.Item("profile1").Value bit in its current
surroundings..

"raj chahal" <in**@digitise.info> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi there

I need to be able to print on screen when I check if a value within a db

<td>
<% if ((Recordset1.Fields.Item("profile1").Value) <>
"") then response.Write"Pro1<br>" &
Recordset1.Fields.Item("profile1").Value%>

</td>

I am checking if profile1 contains any text if not don't print anything.

If
yes then print the heading and the contents .
Now the problem is that I cannot seem to check the value and print the

same
value.
If I check profile2 instead of profile1 (which contains a value) then
profile1 is printed.
At the moment only Pro1 is written to the screen but the contents of
profile1 is not, eventhough profile1 is not empty.

What could be wrong ??

Thanks


Mar 20 '06 #6

pulaki wrote:
Just in case you are unframiliar with NULL....

a Null value in a data field can appear as an empty string ("")....but it is
NOT an empty string. It is a value and it behaves like a value.

So, if a field contains a NULL value, then it may appear as though it is
empty, but technically, it is not empty. Perhaps you just want to add to
your conditional test:

if ( (..... <> "") AND (..... <> "Null") ) then .....

Just a thought.


Shouldn't that be

If ( (..... <> "") And ( Not IsNull(.......)) ) Then ..... ?

<>"Null" means is not equal to a string with the value "Null" - as
opposed to a null value. doesn't it? Or am I confusing database nulls
and vbscript nulls?

--
Mike Brind

Mar 20 '06 #7
Patrice wrote:
if ((Recordset1.Fields.Item("profile1").Value) <>
"") then response.Write"Pro1<br>" &
Recordset1.Fields.Item("profile1").Value


...Similarly if the value is null and if I remember well
my ASP days, it will print Pro1 (as this is not "") but
you won't see anything either.


Afraid you don't remember your VBScript correctly, Patrice. If either
argument is Null, the inequality returns Null:
http://msdn.microsoft.com/library/en...486d5f1e30.asp
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Mar 20 '06 #8

Mike Brind wrote:
pulaki wrote:
Just in case you are unframiliar with NULL....

a Null value in a data field can appear as an empty string ("")....but it is
NOT an empty string. It is a value and it behaves like a value.

So, if a field contains a NULL value, then it may appear as though it is
empty, but technically, it is not empty. Perhaps you just want to add to
your conditional test:

if ( (..... <> "") AND (..... <> "Null") ) then .....

Just a thought.

Shouldn't that be

If ( (..... <> "") And ( Not IsNull(.......)) ) Then ..... ?


Correction:

If ( (..... <> "") And (IsNull(.......)=False) ) Then ..... ?

<>"Null" means is not equal to a string with the value "Null" - as
opposed to a null value. doesn't it? Or am I confusing database nulls
and vbscript nulls?

--
Mike Brind


Mar 21 '06 #9
I wonder why I didn't thought VBScript would be clever enough to be
consistent with the usual NULL behavior ;-)

So, it would finally likely left us with non visible characters in profile1
(perhaps because of the use of CHAR). Hopefully the original poster will pop
up once checked...

--
Patrice

"Dave Anderson" <GT**********@spammotel.com> a écrit dans le message de
news: eH**************@TK2MSFTNGP14.phx.gbl...
Patrice wrote:
if ((Recordset1.Fields.Item("profile1").Value) <>
"") then response.Write"Pro1<br>" &
Recordset1.Fields.Item("profile1").Value


...Similarly if the value is null and if I remember well
my ASP days, it will print Pro1 (as this is not "") but
you won't see anything either.


Afraid you don't remember your VBScript correctly, Patrice. If either
argument is Null, the inequality returns Null:
http://msdn.microsoft.com/library/en...486d5f1e30.asp
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms. Please do not
contact me directly or ask me to contact you directly for assistance. If
your question is worth asking, it's worth posting.

Mar 21 '06 #10
>> If ( (..... <> "") And ( Not IsNull(.......)) ) Then ..... ?
Correction:
If ( (..... <> "") And (IsNull(.......)=False) ) Then ..... ?


Why the correction?

Mar 21 '06 #11
Hi there again..

Thanks for your help.. I have now discovered something weird that explains
the problem below..
When I check froa a value or print a value from recordset the value is
emptied ! This is why I have the problem.

I tested with the below code :

1 <%
2 response.Write "profile1 - " &
(Recordset1.Fields.Item("profile1").Value) & "-<br> "

3 ' if ((Recordset1.Fields.Item("profile1").Value) <> null) then
4 response.Write "Pro1 " & (Recordset1.Fields.Item("profile1").Value)
5 ' End IF
6 %>

When I execute the above the response is :

profile1 - Photoshop and guitar playing-
Pro1

Therefore the value of (Recordset1.Fields.Item("profile1").Value) is now
somehow empty in line 4 !

When I comment line 2 the response is :

Pro1 Photoshop and guitar playing

So now (Recordset1.Fields.Item("profile1").Value) in line 4 prints !

The value of (Recordset1.Fields.Item("profile1").Value) is also emptied on
any checking for null.
I know line 3 may be incorrect for the moment but this is commented for this
test.

Any ideas on this pls ?
Thanks again
"raj chahal" <in**@digitise.info> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi there

I need to be able to print on screen when I check if a value within a db

<td>
<% if ((Recordset1.Fields.Item("profile1").Value) <>
"") then response.Write"Pro1<br>" &
Recordset1.Fields.Item("profile1").Value%>

</td>

I am checking if profile1 contains any text if not don't print anything. If yes then print the heading and the contents .
Now the problem is that I cannot seem to check the value and print the same value.
If I check profile2 instead of profile1 (which contains a value) then
profile1 is printed.
At the moment only Pro1 is written to the screen but the contents of
profile1 is not, eventhough profile1 is not empty.

What could be wrong ??

Thanks

Mar 21 '06 #12

Anthony Jones wrote:
If ( (..... <> "") And ( Not IsNull(.......)) ) Then ..... ?

Correction:
If ( (..... <> "") And (IsNull(.......)=False) ) Then ..... ?


Why the correction?


Is the first one valid?

Mar 21 '06 #13
Mike Brind wrote:
Anthony Jones wrote:
If ( (..... <> "") And ( Not IsNull(.......)) ) Then ..... ?

Correction:
If ( (..... <> "") And (IsNull(.......)=False) ) Then ..... ?


Why the correction?


Is the first one valid?


Why go through all this rigmarole? A simple

If len(yourvariable)>0 then
'it's got a value
else
'it's either null or an empty string
end if

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"
Mar 21 '06 #14
Never saw this. You may want also to use "view source" in case you would
have some kind of html markup inside the value that causes a problem in
rendering and make the value appears to be empty when it would be just not
rendered.

The first test I can think off would be something like :
Response.Write Now() & "<br>" ' To make sure the test is current
Response.Write Recordset1.Fields.Item("profile1").Value="Photosho p and
guitar playing" & "<br>"
Response.Write Recordset1.Fields.Item("profile1").Value & '"<br>"
Response.Write Recordset1.Fields.Item("profile1").Value="Photosho p and
guitar playing" & "<br>"
Response.Write Recordset1.Fields.Item("profile1").Value & "<br>"

To make sure if printing the value is really destructive. I suppose
Recordset1 is a usual ADOB recordset ?

Good luck.
--
Patrice

"raj chahal" <in**@digitise.info> a écrit dans le message de news:
uY*************@TK2MSFTNGP12.phx.gbl...
Hi there again..

Thanks for your help.. I have now discovered something weird that explains
the problem below..
When I check froa a value or print a value from recordset the value is
emptied ! This is why I have the problem.

I tested with the below code :

1 <%
2 response.Write "profile1 - " &
(Recordset1.Fields.Item("profile1").Value) & "-<br> "

3 ' if ((Recordset1.Fields.Item("profile1").Value) <> null) then
4 response.Write "Pro1 " &
(Recordset1.Fields.Item("profile1").Value)
5 ' End IF
6 %>

When I execute the above the response is :

profile1 - Photoshop and guitar playing-
Pro1

Therefore the value of (Recordset1.Fields.Item("profile1").Value) is now
somehow empty in line 4 !

When I comment line 2 the response is :

Pro1 Photoshop and guitar playing

So now (Recordset1.Fields.Item("profile1").Value) in line 4 prints !

The value of (Recordset1.Fields.Item("profile1").Value) is also emptied on
any checking for null.
I know line 3 may be incorrect for the moment but this is commented for
this
test.

Any ideas on this pls ?
Thanks again
"raj chahal" <in**@digitise.info> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi there

I need to be able to print on screen when I check if a value within a db

<td>
<% if ((Recordset1.Fields.Item("profile1").Value)
<>
"") then response.Write"Pro1<br>" &
Recordset1.Fields.Item("profile1").Value%>

</td>

I am checking if profile1 contains any text if not don't print anything.

If
yes then print the heading and the contents .
Now the problem is that I cannot seem to check the value and print the

same
value.
If I check profile2 instead of profile1 (which contains a value) then
profile1 is printed.
At the moment only Pro1 is written to the screen but the contents of
profile1 is not, eventhough profile1 is not empty.

What could be wrong ??

Thanks


Mar 21 '06 #15

"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...

Anthony Jones wrote:
> If ( (..... <> "") And ( Not IsNull(.......)) ) Then ..... ?

Correction:
If ( (..... <> "") And (IsNull(.......)=False) ) Then ..... ?


Why the correction?


Is the first one valid?


I don't see anything wrong with it. IsNull returns a boolean which is
flipped then And'ed with the expression prior to it which also returns a
boolean.

Still I prefer Bob's solution. :)

Anthony.
Mar 21 '06 #16

Anthony Jones wrote:
"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...

Anthony Jones wrote:
>> If ( (..... <> "") And ( Not IsNull(.......)) ) Then ..... ?

>Correction:
>If ( (..... <> "") And (IsNull(.......)=False) ) Then ..... ?

Why the correction?


Is the first one valid?


I don't see anything wrong with it. IsNull returns a boolean which is
flipped then And'ed with the expression prior to it which also returns a
boolean.

Still I prefer Bob's solution. :)

Anthony.


So do I. It's the one I use - I don't use IsNull very often at all in
VBScript. I generally use AND [value] IS NOT NULL in my SQL to prevent
nulls ever getting to the recordset....

--
Mike Brind

Mar 21 '06 #17
Patrice wrote:
I wonder why I didn't thought VBScript would be clever enough
to be consistent with the usual NULL behavior ;-)


One of the many comforts of JScript is its Boolean coercion. Since null and
empty string each coerce to false, this is sufficient in JScript:

if (Recordset1.Fields("profile1").Value) ...

Of course, this leads to one potential obstacle -- numeric zero is also
"false". Never hurts to know your data...

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Mar 21 '06 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Guy Hocking | last post: by
10 posts views Thread by Thomas | last post: by
12 posts views Thread by Brad Baker | last post: by
1 post views Thread by Yoni | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.