|
it
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
problem with conditional response.write
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 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 > > 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 > > 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 >> >> > > Patrice wrote:
>>> if ((Recordset1.Fields.Item("profile1").Value) <> Afraid you don't remember your VBScript correctly, Patrice. If either >>> "") 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. 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. 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. > Patrice wrote:
> I wonder why I didn't thought VBScript would be clever enough One of the many comforts of JScript is its Boolean coercion. Since null and > to be consistent with the usual NULL behavior ;-) 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. 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 > > > > > > > pulaki wrote:
> Just in case you are unframiliar with NULL.... Shouldn't that be> > 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. > 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 Mike Brind wrote:
Show quote > pulaki wrote: Correction:> > 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 ..... ? 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 >> If ( (..... <> "") And ( Not IsNull(.......)) ) Then ..... ? Why the correction?>Correction: >If ( (..... <> "") And (IsNull(.......)=False) ) Then ..... ? Anthony Jones wrote:
> >> If ( (..... <> "") And ( Not IsNull(.......)) ) Then ..... ? Is the first one valid?> > >Correction: > >If ( (..... <> "") And (IsNull(.......)=False) ) Then ..... ? > > Why the correction? Mike Brind wrote:
> Anthony Jones wrote: Why go through all this rigmarole? A simple>>>> If ( (..... <> "") And ( Not IsNull(.......)) ) Then ..... ? >> >>> Correction: >>> If ( (..... <> "") And (IsNull(.......)=False) ) Then ..... ? >> >> Why the correction? > > Is the first one valid? 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" "Mike Brind" <paxton***@hotmail.com> wrote in message I don't see anything wrong with it. IsNull returns a boolean which isnews: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? > flipped then And'ed with the expression prior to it which also returns a boolean. Still I prefer Bob's solution. :) Anthony. Anthony Jones wrote:
Show quote > "Mike Brind" <paxton***@hotmail.com> wrote in message So do I. It's the one I use - I don't use IsNull very often at all in> 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. VBScript. I generally use AND [value] IS NOT NULL in my SQL to prevent nulls ever getting to the recordset.... -- Mike Brind 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 > > 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 > > 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="Photoshop and Response.Write Recordset1.Fields.Item("profile1").Value & '"<br>" guitar playing" & "<br>" To make sure if printing the value is really destructive. I suppose Response.Write Recordset1.Fields.Item("profile1").Value & "<br>" 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 >> >> > > |
|||||||||||||||||||||||