Type '<typename>' must define operator '<operator>' to be used in a 'For' statement

A For loop specifies a counter variable of a type that does not support a required operator.

The counter variable in a For loop can be of any data type that supports all of the following operators:

  • Greater than or equal (>=)

  • Less than or equal (<=)

  • Addition ()

  • Subtraction (-)

If you use a numeric data type for the counter variable, all the preceding operators are supported. If you use a user-defined class or structure, you must define all the preceding operators on that class or structure.

Note also that the data types of the start, end, and step expressions in the For statement must widen to the data type of the counter variable. If the counter variable is a user-defined class or structure and the start, end, or step expression is of a different type, you must define the CType conversion operator to accomplish the necessary conversion.

Error ID: BC33038

To correct this error

  1. Make sure the spelling of the counter-variable data type is correct.

  2. If you are using a user-defined class or structure for the counter variable, define all the required operators on that class or structure.

  3. Depending on the data types of the start, end, and step expressions, you might have to define one or more CType conversion operators to convert them to the counter variable data type.

See Also

Tasks

How to: Define an Operator

How to: Define a Conversion Operator

Concepts

Operator Procedures

Reference

For...Next Statement (Visual Basic)

Operator Statement

CType Function