Converting a String to Integer

Results 1 to 4 of 4

Thread: Converting a String to Integer

  1. #1
    Bob Jonez Guest

    Default Converting a String to Integer

    How do I convert a string to an integer? I have used the following code and get a data type mismatch. I need to cast the "detailPKEY" variable to an Integer to perform a lookup in my database,<BR><BR>if anyone has an idea please let me know-<BR><BR>&#060;%<BR>dim detailPKEY<BR>detailPKEY = CStr(Request.Form("userPKEY"))<BR>Set dchosts = Server.CreateObject("ADODB.Connection")<BR> dchosts.Open "DATABASE=demohosts.csv;DSN=dchosts;UID=;Password= ;"<BR> strSQL="SELECT * FROM demohosts.csv" _ <BR> & " WHERE PKEY= " & CInt(detailPKEY) *** Error Here ***<BR> Set results=dchosts.Execute(strSQL)<BR> <BR> %&#062;<BR><BR>Thanks,<BR><BR>Bob

  2. #2
    Join Date
    Dec 1969
    Posts
    19,082

    Default RE: Converting a String to Integer

    you have an integer type there, unless you&#039ve tried to CInt() an alphabetic string (i.e. can&#039t convert to an integer.)<BR><BR>what&#039s your actual error message? it may well be useful (programmers wouldn&#039t build them in if they weren&#039t useful)<BR><BR>jason

  3. #3
    Bob Jonze Guest

    Default RE: Converting a String to Integer

    Jason,<BR><BR>Here is my error message:<BR><BR>Microsoft VBScript runtime error &#039 800a000d&#039 <BR><BR>Type mismatch: &#039CInt&#039 <BR><BR>/democenter/hostDetails.asp, line 13 <BR><BR>The variable, detailPKEY, is a numeric primary key in my database. I am simply trying to pull out an isolated record with where condition of the primary key. <BR><BR>Let me know-<BR><BR>Bob

  4. #4
    peterjl@austec.net.au Guest

    Default RE: Converting a String to Integer

    I do not know why you do use the CStr() function when you first retrieve the value from the the form variable. I think that if you did not use either CStr() or CInt(), that you code should work. <BR><BR>What you need to do is to check that you have spelt the name of the form varable exactly as you did in the Form page. <BR><BR>Whenever my asp is having trouble with input variable, I use the following script to debug the input:<BR><BR>-------------------------------------------------------------<BR>&#060;Script language="vbscript" runat="server"&#062;<BR>sub ShowVars<BR> dim f,ff<BR> Response.Write "&#060;table bgcolor=white&#062;&#060;tr&#062;&#060;td&#062;"<B R> Response.Write "&#060;font face=arial size=1 color=green&#062; ==========Form==========="<BR> for each f in Request.Form<BR> Response.Write "<BR>&#060;font color=green&#062;***[" & f & "] = &#039" & Request.Form(f) & "&#039"<BR> next<BR> Response.Write "<BR> ==========Query==========="<BR> for each f in Request.QueryString<BR> Response.Write "<BR>***[" & f & "] = &#039" & Request.QueryString(f) & "&#039"<BR> next<BR> Response.Write "<BR> ==========Cookie==========="<BR> for each f in Request.Cookies<BR> if Request.Cookies(f).Count &#062; 0 then<BR> for each ff in Request.Cookies(f)<BR> Response.Write "<BR>***[" & f & "].[" & ff & "] = &#039" & Request.Cookies(f)(ff) & "&#039"<BR> next<BR> else<BR> Response.Write "<BR>***[" & f & "] = &#039" & Request.Cookies(f) & "&#039"<BR> end if<BR> next<BR> Response.Write "<BR> ==========Session==========="<BR> for each f in Session.Contents<BR> Response.Write "<BR>***[" & f & "] = &#039" & Session(f) & "&#039"<BR> next<BR> Response.Write "&#060;/font&#062;&#060;/td&#062;&#060;/tr&#062;&#060;/table&#062;<BR>"<BR>end sub<BR><BR>&#060;/script&#062;<BR>---------------------------------------------------------------<BR><BR>This is just pasted into my script near the top, and then i just place a line:<BR><BR>&#060;% ShowVars %&#062;<BR>wherever I need to see the valiables, and all form,querystring, cookies, session variables are displayed in the resulting page.<BR><BR>To turn this debugging off I just comment the line thus:<BR>&#060;%&#039 ShowVars %&#062;<BR><BR>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •