Hi!
I am facing a problem with my ASP application. I use an ASP page to Select, Insert, Update and Delete records from a SQL Server database table. Table is defined as follows.
CategoryID, Datatype: int, Primary Key
CategoryName, Datatype: nvarcahr, Null not allowed
Description, Datatype: ntext, Null allowed
Picture, Datatype: image, Null allowed
(Note: If you have SQL Server installed on your system then you probably know this table. It’s the Categories table from Northwind database.)
My data entry form is a simple HTML form with no consideration for type of data. This means that I have the same input fields for all types of data, i.e. all are of type text. Problem arises when I try to insert a record. If I leave the picture field empty, I get no error and record in inserted in the table. But, when I type something in picture field and hit insert button, I get this error.
VBScript Error: Variable is undefined
Error Number: 500
Source: Microsoft VBScript runtime error
HelpFile:
HelpContext: 0
Because my relevant ASP function has “On Error Resume Next” statement on top, my code passes the error line without breaking my application. Interesting thing is that my code still manages to insert the record in the table. But my error handler displays the above mentioned error on the page.
By removing the “On Error Resume Next” statement and then debugging my ASP page, I managed to track down the line of code where this error is generated. Its inside a data conversion function. I am copying the function below.
Code:
public function GetVariantValue(data)
if data="" then
GetVariantValue=Empty
else
GetVariantValue=CVar(data)
end if
end function
Input parameter ‘data’ is a value taken from the HTML form. In this particular example, it’s the value of Picture field. If I do not enter anything in Picture field of my form, GetVariantValue returns Empty value and all goes fine. No Errors.
Suppose I entered “abc” in picture field. When ‘data’ parameter reaches GetVariantValue function, it has “abc” stored in it, and according to my debugger, it’s a String. Error occurs when code reaches this line.
Code:
GetVariantValue=CVar(data)
When I hit F11 on this line (I am using Microsoft Visual Interdev for debugging my ASP), I get above mentioned error. As above mentioned error was formatted by my code, I am pasting the actual error displayed by ASP itself.
Error Type:
Microsoft VBScript runtime (0x800A01F4)
Variable is undefined: 'CVar'
It is important to note that all this is happening before I actually call the Insert code, which is stored inside a COM component. That component is programmed in Visual Basic and that’s the reason I am using this GetVariantFunction. My component expects a Variant for the image datatype.
But as I said, I have not entered that component yet. My ASP page is in the process of converting form data into types expected by my component and this GetVariantValue function (or more specifically, CVar function) is unable to convert a String into a Variant. Any guesses?