Object Ref not set to Instance of an Object

< Back
You are here:

Object Ref not set to Instance of an Object

The “Object Reference not set to an Instance of an Object” error may appear when using VB 6, Visual Studio .NET, VB .NET or C# .NET.


General causes of this error include undeclared or improperly declared controls and variables, therefore, ensure that all variables and controls used in code are properly declared.

This error may also occur in IDAutomation 2D Font and Encoder products if the string parameters in the FontEncode subroutine are not initialized to a string that contains data. For example, setting the DataToEncode string parameter to an empty text box may cause the error because the DataToEncode property cannot be empty.

A workaround is to enable a check to test for the text box being empty and set the DataToEncode string appropriately. For example:

Dim DataToEncode as String
Dim EncodedText as String
EncodedText = ""
If TextToEncode.Text = "" Then
DataToEncode = ""
DataToEncode = TextToEncode.Text
End If
QRFontEncoder.FontEncode DataToEncode, 0, 0, 0, 0, EncodedText