Error while trying to convert from String to Variant using CVar function

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

(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.

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.

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?

(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.

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.

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?

Just a thought...

Cvar is a VB function... as far as I know, it's not available in VBScript, as ALL variables default to variant type in VBScript.

I think that your error message is telling you this, when it says that Cvar doesn't exist. I would just take the Cvar function out of the code and seewhat happens.

Re: Error while trying to convert from String to Variant using CVar function

Originally posted by MrWizard
Just a thought...

Cvar is a VB function... as far as I know, it's not available in VBScript, as ALL variables default to variant type in VBScript.

I think that your error message is telling you this, when it says that Cvar doesn't exist. I would just take the Cvar function out of the code and seewhat happens.

Tim

Thanks. You are right. There is no CVar function in VBScript. Somehow I never thought that the error message was telling me this . Other conversion functions like CBool, CInt etc. worked fine so it never came to my mind that VBScript may not have the CVar function.