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.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Error while trying to convert from String to Variant using CVar function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-11-03, 14:31
nauman73 nauman73 is offline
Registered User
 
Join Date: Jun 2003
Location: Pakistan
Posts: 2
Error while trying to convert from String to Variant using CVar function

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?
Reply With Quote
  #2 (permalink)  
Old 06-11-03, 15:04
MrWizard MrWizard is offline
Registered User
 
Join Date: Mar 2003
Location: Atlanta, GA
Posts: 191
Re: Error while trying to convert from String to Variant using CVar function

Quote:
Originally posted by nauman73
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?
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
__________________
Tim
Reply With Quote
  #3 (permalink)  
Old 06-11-03, 18:00
nauman73 nauman73 is offline
Registered User
 
Join Date: Jun 2003
Location: Pakistan
Posts: 2
Thumbs up Re: Error while trying to convert from String to Variant using CVar function

Quote:
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.

Thanks again.
Reply With Quote
  #4 (permalink)  
Old 07-01-03, 04:40
JonathanB JonathanB is offline
Registered User
 
Join Date: Feb 2002
Location: North Wales, UK
Posts: 114
Note: the datatype "Image" is used to store binary data (blob).
__________________
J^ - web | email
newsASP Developer
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On