Browsing the ASP category

Microsoft VBScript runtime error ‘800a0006’ – Overflow: ‘cint’

I have some server-side validation checks (as should you!).  For whole numbers, I surround my data in the CInt() function to convert the value to an integer.  Actually, I have a separate function that I made (to replicate an existing MS Access function) called “nz” that turns a null value into zero…

But I got an “overflow” error and couldn’t figure out why.  The solution: the number I was trying to sanitize was too big: integers can only be up to ~32,000.  I instead changed to use the CLng() function

Read the article

  • 05.13.2017
  • ASP

Be careful what you name variables

I had a Classic ASP page that was halting on the script.  It was running a loop, but wasn’t iterating through each item correctly.

The problem was that it was a FOR loop, and the variable for each entry was “i”.  The loop was calling a function, and in the function, it was calling a different FOR loop, also with the variable “i”.  When I named the variable something else, it worked!

Read the article

  • 07.26.2016
  • ASP

Classic ASP Overflow: ‘cint’

For my classic ASP site, I got the following error:

Microsoft VBScript runtime error ‘800a0006’

Overflow: ‘cint’

This occurs when you try to convert data to an integer, that shouldn’t be.

My database type was “float” (so I was okay there), and there was only one record in the database – which had a decimal value.  But the ASP Code was using the CInt() function – and causing an error; I’m still not sure why.  The solution was to just use CDBL() (convert to double) – which solved it

Read the article

  • 05.17.2016
  • ASP

ASP function returning the wrong results

I had a Classic ASP function that was returning the wrong value after running a query.  The problem was that I copied a set of functions from a previous project to work on this “new” project.  I put these functions at the bottom of the file.  I wrote my own, new, function, but gave it the same name as an existing function (found at the bottom of the script).  THAT was the function that was being run, instead of the intended one (at the top)

 

Lesson learned: Classic ASP allows you to have multiple functions named the same thing – make sure the function you’re running is the intended one!

Read the article

  • 03.23.2016
  • ASP

Classic ASP: ‘ASP 0104 : 80004005’

I received the following error in my Classic ASP app:

Request object error ‘ASP 0104 : 80004005’

Operation not Allowed

Note: in Internet Explorer, I just get the unhelpful response “the website cannot display the page.”  It was in Chrome that I’m able to view the helpful error.

The problem was that there was too much information being saved into one of the fields of my database.  The limit was set as a “text” field datatype which allowed for ~65,000 characters.  The Value saved in the database was somehow (much) more than that, and when the user when to “save” the record (again), that’s when the error occurred.

Read the article

  • 03.11.2016
  • ASP

ASP Custom Function for null-zero

function nz(TheValue)

 

  if (isnull(TheValue)) or (TheValue = “”) then

                  nz = 0

  else

                  nz = TheValue

  end if

 

  ‘ Replace commas with nothing

  nz = replace(nz,”,”,””)

 

end function

Read the article

  • 01.09.2016
  • ASP

SQL LIKE on a number doesn’t work

A coworker had a SQL statement that was performing a search.  The criteria may/may not be there, so we had the WHERE criteria of:

 qry = qry & ” WHERE field_name LIKE %'” & my_variable & “‘%”

the problem was that the field was numeric; so if the value was blank, it was reading it as:

WHERE field_name LIKE ‘%%’

The solution: when building the query (we’re using Classic ASP), only include that line if the value is not zero:

 

If my_variable <> 0 then

qry = qry & ” WHERE field_name =” &my_variable

End if

 

Notes:

Read the article

classic ASP function that returns a recordset

I figured rather than use the “Dictionary” method, I might as well just have my function return the recordset; then I can just call the columns directly:

 

function GetInfoFromID(ID)

                qry = “SELECT …. WHERE  id=” & cint(ID)

                set rs = GetRecordset(sConnRPS, qry)

                if rs.RecordCount <> 0 then

                                set GetInfoFromID = rs

                end if

               

end function

 

To use:

 

IDInfo = GetInfoFromID(ID)

response.write IDInfo(“foo”)

 

Read the article

  • 10.12.2015
  • ASP

classic asp function return dictionary from recordset

I’m trying to simulate object oriented programming in Classic ASP.  I have a function that returns a recordset.  I can’t use an associate array, so instead I’m using the “Dictionary”.

This worked great:

function dictionaryTest(myValue)

   set d=CreateObject(“Scripting.Dictionary”)

  d.add “test”, myValue

  set dictionaryTest = d

end function

 set myFields = dictionaryTest(“foo”)

response.write myFields.Item(“test”)

found here:

http://www.tek-tips.com/viewthread.cfm?qid=1641047

 

However when I tried to retrieve values from a recordset (instead of hard-coded), I got various errors, including:

 

ADODB.Field error ‘80020009’   Object is no longer valid.

The problem had to do with the Dictionary storing a “pointer” to the value, instead of the actual value. So when the recordset was closed (in my function), it wasn’t available in the function.  The solution: trim the values!

function GetInfoFromID(ID)

                 qry = “SELECT …WHERE id=” & cint(ID)

                set rs = GetRecordset(connection_string, qry)

                if rs.RecordCount <> 0 then

                                Dim d

                                Set d=Server.CreateObject(“Scripting.Dictionary”)

                                d.Add “foo”, trim(rs(“bar”))

                end if

 

               set GetInfoFromID = d

 

end function

Read the article

  • 10.12.2015
  • ASP

Classic ASP export to Excel – buffer size limit exceeded error

I was trying to export a query; a large data dump (i.e. many rows) into Excel from my Classic ASP application. I got an error: “buffer size limit exceeded”. I thought the only solution was a setting on the web server (that I didn’t have access to). I think there’s a default limit (say, 4MB?) on the file size that is allowed.

Solution: add this to the top of the file:

<% Response.Buffer = False %>

Read the article

  • 09.29.2015
  • ASP