Solved

Why is my code not working?

Posted on 2004-10-13
15
230 Views
Last Modified: 2012-08-13
Seems to be a simple enough problem but I am unable to get the correct results. The erring line is as below:

<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%if ((myRS("Release")=0) or (Trim(myRS("Release")) = "") or isNull(myRS("Release"))) then Response.Write "checked" end if%> >No

Its giving me the error

Microsoft VBScript runtime error '800a000d'

Type mismatch: '[string: " "]'

Please help!!

A.
0
Comment
Question by:arunatata
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +3
15 Comments
 
LVL 5

Expert Comment

by:waelothman
ID: 12303840
<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%if ((myRS("Release")="") or (Trim(myRS("Release")) = "") or isNull(myRS("Release"))) then Response.Write "checked" end if%> >No

myRS("Release") seems to be string
0
 
LVL 5

Expert Comment

by:waelothman
ID: 12303847
you can't compare string with numeric (0)
0
 
LVL 15

Expert Comment

by:Colosseo
ID: 12303858
Hi

try with quotes around the 0 like so

<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%if ((myRS("Release")="0") or (Trim(myRS("Release")) = "") or isNull(myRS("Release"))) then Response.Write "checked" end if%> >No

as 0 it is an integer but as "0" it is a string

HTH

Scott
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:arunatata
ID: 12303908
I did that with another - using value="1" - and that worked. For some reason it doesn't like the value " " in the database. If I have 0 or 1 or Null in the database it works fine...only for the spaces or blanks it has problems.

A.
0
 

Author Comment

by:arunatata
ID: 12303918
I tried with the quotes around the "0" and that didn't work either.
0
 
LVL 5

Expert Comment

by:waelothman
ID: 12304053
<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%if ((cint(myRS("Release"))=0) or (Trim(myRS("Release")) = "") or isNull(myRS("Release"))) then Response.Write "checked" end if%> >No
0
 

Author Comment

by:arunatata
ID: 12304080
Not that either. As i mentioned in my post above - the problem is with the blank spaces - not the 0 or 1 or Null values in the database. I've verified with all three and only the spaces is giving me an error.
0
 
LVL 5

Assisted Solution

by:waelothman
waelothman earned 150 total points
ID: 12304222
it is not in database  ASp not allow you to compare string with number
 myrec("fieldname") always catched as string even if the field is numeric
0
 
LVL 10

Expert Comment

by:m8rix
ID: 12304336
Hi arunatata,

waelothman is correct, you can't compare string with numeric (0) however here is some code to replace what you currently have, it is a bit longer, but it is the only way... and it WILL fix your problem.

Cheers!

<%
strdatabase = " "
IsZero = false
If isNumeric(strdatabase) Then
      If strdatabase = 0 Then IsZero = true
End If
%>
<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%if (IsZero) or (Trim(strdatabase) = "") or (isNull(strdatabase)) then Response.Write "checked" end if%> >No
0
 
LVL 10

Accepted Solution

by:
m8rix earned 350 total points
ID: 12304350
Oops! sorry arunatata, I posted you the code that I used for testing... here is the modified version of your code:

<%
IsZero = false
If isNumeric(myRS("Release")) Then
      If myRS("Release") = 0 Then IsZero = true
End If
%>
<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%if (IsZero) or (Trim(myRS("Release")) = "") or isNull(myRS("Release"))) then Response.Write "checked" end if%> >No
0
 

Author Comment

by:arunatata
ID: 12304427
Nope - that doesn't work either. I am posting the entire page below - maybe something here will strike out as wrong..


<%@ Language=VBScript %>
<%Response.Buffer = "true"%>
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</head>
<body>
<form action="SearchResultsUpdateData.asp" Method="Post" id="form5" name="form5">
<%
PONumber = Request("PONumber")
Output = Request("Output")
Key1 = request("Key1")

Dim myConn                  
Dim myRS                  
Dim myRS1
Dim stmt            
Dim DText            
Dim i            

Set myRS = Server.CreateObject("ADODB.Recordset")
Set myRS1= Server.CreateObject("ADODB.Recordset")
Set myConn = Server.CreateObject("ADODB.Connection")
DText="Provider=SQLOLEDB;Server=abc;Initial Catalog=sand;User ID=sa"
myConn.Open DText
stmt1 = "select * from DesignMain where [PO Number] = '"&PONumber&"'"      
myRS1.Open stmt1, myConn,1,3
stmt = "Select * from BoardDesignYN where [PO Number] = '"&PONumber&"'"
myRS.Open stmt,myConn,1,3

IsZero = False

if isNumeric(myRS("Release to Production")) then
      if myRS("Release to Production") = 0 then
           IsZero = True
      end if
end if
%>


<td><b>Net List</b>
<input TYPE="radio" NAME="NetList" value="1" <%if (myRS("Net List"))=1 then Response.Write "Checked" end if%>>Yes
<input TYPE="radio" NAME="NetList" value="0" <%if (myRS("Net List"))=0 then Response.Write "Checked" end if%>>No</td>
</tr><br>
<% 'The section above works fine. I didn't have to go through any integer or string conversions for this.

'The section below is the problem area.
%>


<td><b>Release to Production?</b>
<input TYPE="radio" NAME="Release" value="1" <%if (myRS("Release To Production"))=1 then Response.Write "Checked" end if%>>Yes
<input TYPE="radio" NAME="Release" value="0" <%if ((IsZero) or (Trim(myRS("Release to Production")) = "") or isNull(myRS("Release to Production"))) then Response.Write "checked" end if%>>No
</td>
</tr>




<tr><td align="center" colspan="2"><input TYPE="submit" VALUE="Update" id="submit" name="submit"></td></tr>


</table>

<%      
myRS.Close
set myRS=nothing
%>


</table>



</form>

</body>
</html>
0
 
LVL 10

Expert Comment

by:m8rix
ID: 12304814
Ok forget what I suggested before, try replacing this WHOLE section:

<td><b>Net List</b>
<input TYPE="radio" NAME="NetList" value="1" <%if (CStr(myRS("Net List"))="1") then Response.Write "Checked" end if%>>Yes
<input TYPE="radio" NAME="NetList" value="0" <%if (Cstr(myRS("Net List"))="0") then Response.Write "Checked" end if%>>No</td>
</tr><br>
<% 'The section above works fine. I didn't have to go through any integer or string conversions for this.

'The section below is the problem area.
%>


<td><b>Release to Production?</b>
<input TYPE="radio" NAME="Release" value="1" <%if (CStr(myRS("Release To Production"))="1") then Response.Write "Checked" end if%>>Yes
<input TYPE="radio" NAME="Release" value="0" <%if (CStr(myRS("Release to Production"))="1") or (Trim(CStr(myRS("Release to Production"))) = "") or isNull(myRS("Release to Production")) then Response.Write "checked" end if%>>No
</td>
</tr>
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12305392
what is the datatype of field "release to production" and try len(trim(myRs("Release to production")) = 0 instead of ltrim(myRs("Release to production") = ""
0
 
LVL 3

Expert Comment

by:Kupi
ID: 12305913
What about this?

<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%If CInt("0" & Trim(myRS("Release"))) = 0 Then Response.Write "checked" End If%>>No

This combines all your conditions (= 0, = "", = NULL) in one.

Kupi
0
 
LVL 5

Expert Comment

by:waelothman
ID: 12306364
please     if myRS("Release to Production") = "0" then
as well as in all code
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question