Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Error  ---   Type mismatch: 'cint'

Posted on 2003-03-25
8
Medium Priority
?
1,178 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
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
Industry Leaders: 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!

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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…
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
Course of the Month10 days, 6 hours left to enroll

569 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