?
Solved

Error  ---   Type mismatch: 'cint'

Posted on 2003-03-25
8
Medium Priority
?
1,165 Views
Last Modified: 2013-12-03
Hi! I have the following code used for paging through records generated from a database.
It does seem to work to an extent that it does output the desierd amount of records and also does a page count (e.g Page 1 of 4). The problem though is that the backward and forward button does not work. Keep on getting the message -->   Error Type  -->  Type mismatch: 'cint'

Have tried replacing Request.Form with Request.QueryString but buttons do not do anything. Also no error message appears.

Code ---->


Sub showProductCategories(connobj)
     
     Dim intI
     Dim strHTML
     Dim q          
     q = chr(34)
     Dim rs          ' Creates recordset to show categories from database
     Set rs = Server.CreateObject ("ADODB.Recordset")
     sql = "Select * FROM productCategories ORDER BY categoryName ASC;"
     
     
     rs.Open sql, connobj, adOpenStatic, adLockReadOnly, adCmdText
     
     
     if Request.Form ("backward") = "test" then
          strActPage = cint(Request.Form ("txtPosition")) - 1
     elseif Request.Form ("forward") = "test2" then
          strActPage = cint(Request.Form ("txtPosition")) + 1
     else
          strActPage = 1
     end     if
     
     rs.PageSize = 4
     rs.AbsolutePage = strActPage
     response.Write "<b>Page " & rs.AbsolutePage & " of " & rs.PageCount & "</b><br><br>"

     

     If not rs.EOF then
               Response.Write "<table border=1 cellPadding=4 cellSpacing=11 width='100%'>"
               Response.Write "<tr>"
         
         intI = 0
          i = 1
          While Not rs.EOF And intI < rs.PageSize
               Response.Write "<td valign=top>" & vbcrlf
               Response.Write "<font face=" & q & "Times New Roman" & q & "><a HREF="& q &"productdetails.asp?id="
               Response.Write rs("categoryID") & q & "><center><b>" & vbcrlf
               Response.Write rs("categoryName") & "<br></a><b></center></b>" & vbcrlf
               Response.Write rs("categorytxt") & "</b>" & vbcrlf
               Response.Write rs("categoryDescription") & "</font>" & vbcrlf
               Response.Write "</td>" & vbcrlf
               if (i mod 2) = 0 then
                    Response.Write "</tr><tr>" & vbcrlf
               end if
               i = i + 1
               
          rs.MoveNext
          IntI = intI + 1
          Wend
     Response.Write "</tr></table>"
     Else
          Response.Write "Sorry no categories were found under this name."
     End if
     
     rs.Close
     Set rs = Nothing
     
     Response.Write strHTML
               
End Sub
%>


       <form method="POST" action="">
              <input type="hidden" name= "txtPosition"value="<%=strActPage%>">
              <INPUT type="submit" value="test" name="backward">
              <INPUT type="submit" value="test2" name="forward">
          </form>

Any help will be greatly appreciated.

Lynx
0
Comment
Question by:lynxvoodoo
[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
8 Comments
 
LVL 7

Accepted Solution

by:
markhoy earned 300 total points
ID: 8203559
cint error means you are trying to convert a string to an integer ie cint("apple") isn't gonna work but cint(6) will (vbscript variables are variant type, unlike vb etc).

if Request.Form ("backward") = "test" then
         strActPage = cint(Request.Form ("txtPosition")) - 1
    elseif Request.Form ("forward") = "test2" then
         strActPage = cint(Request.Form ("txtPosition")) + 1


cint(Request.Form ("txtPosition"))

is this a number to start with ie 1,2,3 etc (and not blank)?

for each fld in request.querystring
response.write fld & " = " & request.querystring(fld) & "<BR>"
next

(works for .form as well).

if Request.Form ("backward") = "test" then
if Request.Form ("txtPosition")) <>"" then

strActPage = cint(Request.Form ("txtPosition")) + 1

end if
end if
0
 
LVL 12

Expert Comment

by:Wouter Boevink
ID: 8203572
You should debug, try displaying the value of Request.Form ("txtPosition"). I guess it's empty.

It's not possible to convert a empty string to an integer. Or it's a character string "abc" and not "23".

CHeck for an empty string

if len(Request.Form("txtPosition")) <> 0 then
  ...do your stuff
else
  ...error
end if

Or if Request.Form("txtPosition") <> "" will do the same but it's slower. (not noticable).
0
 
LVL 4

Expert Comment

by:JNSTAUB
ID: 8203664
where is the declaration of strActPage.
when are you calling your subroutine before to load your page or after? if after the strActpage is empty.
regards
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 7

Expert Comment

by:markhoy
ID: 8203726
Typo in your HTML:

<input type="hidden" name= "txtPosition"value="<%=strActPage%>">


should be:

<input type="hidden" name= "txtPosition" value="<%=strActPage%>">

note the space between name and value!
0
 
LVL 3

Expert Comment

by:keystrokes
ID: 8204855
It seems like one or more value inside the Cint function is blank.  Trace them.
0
 
LVL 4

Expert Comment

by:anderson22
ID: 8206736
Anytime you are confused or don't know when to use Request.Form("var") or Request.QueryString("var"), you can simply use Request("var").  This will look in the QueryString collection for the object and then in the Form collection.

My suggestion on casting is never to do this explicitly.  I would use a function, i.e.:

Function toInteger( obj )
    if Len( obj ) > 0 and _
       IsNumeric( obj ) and _
       not IsEmpty( obj ) then
         toInteger = CInt( obj )
    else
         toInteger = 0
    end if
End Function

**Note:  It is important to note the difference between CInt and Int funtions in VBScript.  CInt will automatically round the number while Int will simply truncate the number.

-rca
0
 
LVL 1

Expert Comment

by:babypris
ID: 8214015
I think the problem is that you're trying to convert a null string into an integer.

You can either try checking the string you wanna convert (see if it's null, if it's null, set it to ""), or try another way of converting. Normally in VB, using val(vbnullstring) will return 0, but I doubt that you can use val function in vb script.

Good luck. Hope it helps!

cheers,
-prisca-
0
 
LVL 58

Expert Comment

by:Gary
ID: 9312873
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by markhoy

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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/…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

764 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