Solved

Why is my code not working?

Posted on 2004-10-13
15
226 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now