Home All Groups Group Topic Archive Search About

problem with conditional response.write



Author
20 Mar 2006 1:02 PM
raj chahal
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

Author
20 Mar 2006 1:22 PM
Patrice
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" <i***@digitise.info> a écrit dans le message de news:
%23dDZC8BTGHA.4***@TK2MSFTNGP14.phx.gbl...
Show quote
> 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
>
>
Author
20 Mar 2006 1:30 PM
raj chahal
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..



Show quote
"raj chahal" <i***@digitise.info> wrote in message
news:%23dDZC8BTGHA.4300@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
>
>
Author
20 Mar 2006 2:38 PM
Patrice
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" <i***@digitise.info> a écrit dans le message de news:
%23%2349EMCTGHA.5***@TK2MSFTNGP12.phx.gbl...
Show quote
> 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" <i***@digitise.info> wrote in message
> news:%23dDZC8BTGHA.4300@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
>>
>>
>
>
Author
20 Mar 2006 9:03 PM
Dave Anderson
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-us/script56/html/adb6e3ac-d925-4987-9d43-f6486d5f1e30.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.
Author
21 Mar 2006 8:52 AM
Patrice
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" <GTSPXOESSGOQ@spammotel.com> a écrit dans le message de
news: eHaOPHGTGHA.5***@TK2MSFTNGP14.phx.gbl...
Show quote
> 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-us/script56/html/adb6e3ac-d925-4987-9d43-f6486d5f1e30.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.
>
Author
21 Mar 2006 2:55 PM
Dave Anderson
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.
Author
20 Mar 2006 7:55 PM
pulaki
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.

Show quote
"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" <i***@digitise.info> wrote in message
> news:%23dDZC8BTGHA.4300@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
> >
> >
>
>
>
Author
20 Mar 2006 8:14 PM
Mike Brind
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
Author
21 Mar 2006 7:50 AM
Mike Brind
Mike Brind wrote:
Show quote
> 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 ..... ?

Show quote
>
> <>"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
Author
21 Mar 2006 9:02 AM
Anthony Jones
>> If ( (..... <> "") And ( Not  IsNull(.......)) ) Then ..... ?

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

Why the correction?
Author
21 Mar 2006 11:33 AM
Mike Brind
Anthony Jones wrote:
> >> If ( (..... <> "") And ( Not  IsNull(.......)) ) Then ..... ?
>
> >Correction:
> >If ( (..... <> "") And (IsNull(.......)=False) ) Then ..... ?
>
> Why the correction?

Is the first one valid?
Author
21 Mar 2006 11:50 AM
Bob Barrows [MVP]
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"
Author
21 Mar 2006 1:28 PM
Anthony Jones
"Mike Brind" <paxton***@hotmail.com> wrote in message
news:1142940781.238360.77770@z34g2000cwc.googlegroups.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.
Author
21 Mar 2006 2:09 PM
Mike Brind
Anthony Jones wrote:
Show quote
> "Mike Brind" <paxton***@hotmail.com> wrote in message
> news:1142940781.238360.77770@z34g2000cwc.googlegroups.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
Author
20 Mar 2006 2:41 PM
Ray Costanzo [MVP]
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


Show quote
"raj chahal" <i***@digitise.info> wrote in message
news:%23dDZC8BTGHA.4300@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
>
>
Author
21 Mar 2006 9:58 AM
raj chahal
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


Show quote
"raj chahal" <i***@digitise.info> wrote in message
news:%23dDZC8BTGHA.4300@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
>
>
Author
21 Mar 2006 11:55 AM
Patrice
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="Photoshop and
guitar playing" & "<br>"
Response.Write Recordset1.Fields.Item("profile1").Value & '"<br>"
Response.Write Recordset1.Fields.Item("profile1").Value="Photoshop 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" <i***@digitise.info> a écrit dans le message de news:
uYkGS6MTGHA.***@TK2MSFTNGP12.phx.gbl...
Show quote
> 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" <i***@digitise.info> wrote in message
> news:%23dDZC8BTGHA.4300@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
>>
>>
>
>

AddThis Social Bookmark Button