Problem while using "CInt"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vini171285
    New Member
    • Apr 2008
    • 60

    Problem while using "CInt"

    Hi,
    Here in this code we have used CInt before Session,If we wont use CInt the code doesn't work in the intended way....and using CInt sometimes gives error..It works for 1 day & the other day shows error...What & why is this problem?? Is there any alternative for "CInt" or we ll hv to include any file..
    Please Help !

    Code:
    <%@ language=VBScript%>
    <% option explicit %>
    <!--#include virtual="/adovbs.inc"-->
    <HTML>
    <BODY>
    <form method=post action="z2.asp">
    Name:<input type=text name=name value=<%=Session("name")%>><BR>
    Password:<input type=password name=pwd>
    <BR>
    <%
    Response.Write CInt(Session("age"))
    %><BR>
    Age:<select name=age>
    <%
    	Dim objConn
    	Set objConn=Server.CreateObject("ADODB.Connection")
    	objConn.ConnectionString="DSN=Info.dsn;uid=vini;pwd=vini"
    	objConn.Open
    
    	Dim sql
    	sql="SELECT * FROM age"
    
    	Dim objRS
    	Set objRS=Server.CreateObject("ADODB.Recordset")
    	objRS.Open sql,objConn
    
    	Dim i
    	i=CInt(Session("age"))
    
    	Do while not objRS.EOF
    		If i=CInt(objRS("num")) Then
    			Response.Write "<option value=" & objRS("num")& " selected>"
    			Response.Write objRS("age") & "</option>"
    		Else
    			Response.Write "<option value=" & objRS("num") & ">"
    			Response.Write objRS("age") & "</option>"
    		End If
    		objRS.MoveNext
    	Loop
    
    	objRS.Close
    	Set objRS=Nothing
    
    	objConn.Close
    	Set objConn=Nothing
    %>
    </select>
    
    <input type=submit>
    </form>
    </BODY>
    </HTML>
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Using CInt casts your variable to an integer but it will error if the value of the variable doesn't contain an integer value e.g it contains a char. Are you certain that objRS("num") is always an integer value?

    What are the errors that are sometimes occuring?

    Dr B

    Comment

    • Vini171285
      New Member
      • Apr 2008
      • 60

      #3
      hi..
      When we use CInt, error is type mismatch..
      but when we remove it ,the value of list box is not stored..it is lost..
      and after sometime if we again put CInt,it works properly..
      and value is retained..
      So,we are just putting CInt for all listboxes one day...
      and next day we are removing CInt so that our program shd run.....

      and also,Sometime we get error such as "Operation Timed Out"...
      This is related to oracle..
      After this error occurs, our programs doesn't run for near about 2 days and after that it starts working automatically..
      we don't know wat the problem is...
      Do u think it is related to hardware or may be some problem with our code??

      Thanks

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        I doubt it's hardware related.

        Is the data you are querying static? If not and your data is changing day to day and the performance of your web page is also changing day to day it would suggest that the data is the cause of the problem.

        Next time you get the type mismatch error comment out the bit that's causing the problem and stick a response.write in to see what the value actually is.

        Also, is your query so big and returning so many results that you'd expect it to cause a time out?

        Comment

        • Vini171285
          New Member
          • Apr 2008
          • 60

          #5
          In our project ther are 4 web pages, there are near about 30-35 list boxes and may be 25-30 text boxes per page..
          and all list boxes are filled from database and data is static..
          and when the time out error occurs,we are not even able to open our database.
          Thanx

          Comment

          • DrBunchman
            Recognized Expert Contributor
            • Jan 2008
            • 979

            #6
            If the data is static then the data can't be the problem. Perhaps the problem is the session variable not being correctly retained?

            Remember that when an asp page errors it ends the current session. Every time you have a timeout it will destroy the session value which may be part of the problem.

            Can you test for the value of that the next time you get a type mis-match?

            Comment

            Working...