Ad Space — Top Banner

?TYPE MISMATCH ERROR

Commodore VIC-20

Severity: Minor

What Does This Error Mean?

?TYPE MISMATCH ERROR means BASIC tried to use a string where a number was expected, or vice versa. The most common cause is confusing numeric variables (A) with string variables (A$). Type LIST to find the line and check the variable types.

Affected Models

  • Commodore VIC-20

Common Causes

  • Assigning a string literal to a numeric variable: LET A = "HELLO"
  • Using a string variable in a numeric function: PRINT SQR(A$)
  • Mixing string and numeric variables in an expression
  • Reading DATA of the wrong type: numeric variable reading string DATA
  • Comparing a number to a string in an IF statement

How to Fix It

  1. Type LIST and go to the line number shown in the error.

    The VIC-20 prints the line number where the type mismatch occurred. Type LIST 100 (or whatever the line number is) to see the offending line.

  2. Check variable names — string variables must end with $.

    In Commodore BASIC V2, A is a numeric variable and A$ is a string variable. If you wrote A = "HELLO" that is a type mismatch — change to A$ = "HELLO".

  3. Check functions are getting the right type.

    Numeric functions (SQR, SIN, INT, ABS) require numeric arguments. String functions (LEFT$, MID$, LEN) require string arguments. LEN(A) causes ?TYPE MISMATCH if A is numeric — use LEN(A$) instead.

  4. Check READ/DATA pairs match their types.

    If you have DATA HELLO,10 and you READ A,B — A is numeric but HELLO is a string. Change to READ A$,B to match the DATA correctly.

Frequently Asked Questions

Is this the same error as on the Commodore 64?

Yes. The VIC-20 and C64 both use Commodore BASIC V2. ?TYPE MISMATCH ERROR is identical in meaning, causes, and fixes on both machines.

Can I check a variable's type in VIC-20 BASIC?

Not directly with a type-check function. But the naming convention is the guide: if the variable name ends in $, it is a string. Otherwise it is numeric.