Connecting Tech Pros Worldwide Forums | Help | Site Map

Invalid use of null

Familiar Sight
 
Join Date: Jul 2006
Posts: 181
#1: Jun 12 '09
Hi, I have looked around and this seems to be a common problem when a database field is empty. I have this and none of the solutions I have seen seem to work. I tried ),"'","<") but that didnt solve anything.


Expand|Select|Wrap|Line Numbers
  1. Response.Write "<tr><td height=""30"" width=""300"" align=""left"" valign=""middle""><font size=""2"">site</font></td>"
  2. Response.Write "<td height=""30"" width=""250"" align=""left"" valign=""middle""><input type=""text"" name=""imageone"" value=""" & Replace(objOptionsAndInfo("imageone"), Chr(34), "&quot;") & """ size=""30"" maxlength=""45""></td></tr>"
If anyone has a solution that would be great.
Thanks
Richard



prabirchoudhury's Avatar
Familiar Sight
 
Join Date: May 2009
Location: Wellington, New Zealand
Posts: 152
#2: Jun 12 '09

re: Invalid use of null


1. Response.Write("html hoes here"); would be like that


Expand|Select|Wrap|Line Numbers
  1.            Response.Write("<table width=500>");
  2.             Response.Write("<tr>");
  3.             Response.Write("<td align=right>");
  4.             Response.Write("<BR>");
  5.             Response.Write(DateTime.Now.ToString());
  6.             Response.Write("</td>");
  7.             Response.Write("</tr>");
  8.             Response.Write("</table>"); 
  9.  
have a look on

Carriage Return and Response.Write Output Issue

:)
GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 143
#3: Jun 12 '09

re: Invalid use of null


Personally, I can't stand response.writing out html. If I have to mix content with code I always come out of vbscript and just type out the html:

Expand|Select|Wrap|Line Numbers
  1. <table>
  2.   <tr>
  3.     <th>Field One</th>
  4.     <th>Field Two</th>
  5.     <th>Field Three</th>
  6.   </tr>
  7.  
  8. <% Do While Not blah.... %>
  9.   <tr>
  10.     <td><%=rs("fieldone")%></td>
  11.     <td><%=rs("fieldtwo")%></td>
  12.     <td><%=rs("fieldtwo")%></td>
  13.   </tr>
  14. <% rs.movenext
  15. Loop %>
  16. </table>
  17.  
If you use a decent editor that highlights code well (I recommend Notepad++), there are obvious benefits.

As to your original question, check if the field isn't empty before you use replace:

Expand|Select|Wrap|Line Numbers
  1. <% If not objOptionsAndInfo("imageone") = "" then Replace(objOptionsAndInfo("imageone"), Chr(34), "&quot;") %> 
Gaz
Familiar Sight
 
Join Date: Jul 2006
Posts: 181
#4: Jun 14 '09

re: Invalid use of null


Thanks to you guys I have sorted it now.
Thanks
Richard
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#5: Jun 15 '09

re: Invalid use of null


Quote:

Originally Posted by GazMathias View Post

Personally, I can't stand response.writing out html. If I have to mix content with code I always come out of vbscript and just type out the html

Gaz

I agree strongly.

Jared
Expert
 
Join Date: Nov 2007
Posts: 126
#6: Jun 17 '09

re: Invalid use of null


Quote:

Originally Posted by GazMathias View Post

Personally, I can't stand response.writing out html. If I have to mix content with code I always come out of vbscript and just type out the html:

I'm not so sure on this one, personally. It's been tested that (extensive) intermingling of dynamic and non-dynamic script causes CPU overhead to increase.


Form a clean code point of view, I just use line continuations when appropriate:

Expand|Select|Wrap|Line Numbers
  1. response.write "I've got a lovely bunch " & _
  2.                       "of coconuts! Deedly, dee! " & _
  3.                       "There they are standing in a row." & _
  4.                       "<big>Big ones!</big>" & _
  5.                       "<small>Small ones!</small>"
  6.  
  7.  
Clean.
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#7: Jun 17 '09

re: Invalid use of null


Quote:

Originally Posted by Nicodemas View Post

I'm not so sure on this one, personally. It's been tested that intermingling dynamic and non-dynamic script causes CPU overhead to increase.

Form a clean code point of view, I just use line continuations when appropriate:

Clean.

line continuations, fine, I don't have a problem with that. I have just seen too many people trying to response.write complex HTML including escaped quote marks. They always lose count of their quotes and can't decipher the error messages.
Expand|Select|Wrap|Line Numbers
  1. response.write "<input type=""text"" value="" &      rs("myTextValue") & "" name=""myTextValue"">" & vbNewLine
Do you see where the error is? the error would be something like "Command expected".

Or they use non-strict or even non-standard HTML because they are trying to avoid using quotes. The only other solution I've liked, is to assign double quotes to a variable
Expand|Select|Wrap|Line Numbers
  1. dim q
  2. q = chr(34)
  3. response.write "<input type=" & q & "text" & q & " value=" & q & _
  4.       rs("myTextValue") & q & " name=" & q & "myTextValue" & q & ">" &_
  5.       vbNewLine
but this is much less-clean than this
Expand|Select|Wrap|Line Numbers
  1. %>
  2. <input type="text" name="myTextValue" value="<%=rs("myTextValue")%>">
  3. <%
I don't know which executes faster, but I know this last is easier to read, write and troubleshoot.

Jared
Reply


Similar ASP / Active Server Pages bytes