Type mismatch
Amstrad Amstrad CPC
Severity: MinorWhat Does This Error Mean?
Type mismatch on the Amstrad CPC means you mixed up strings and numbers in an expression. You tried to use a string where a number was expected, or vice versa. Check the variable types — names ending in $ are strings, all others are numbers.
Affected Models
- Amstrad CPC 464
- Amstrad CPC 664
- Amstrad CPC 6128
- Amstrad CPC Plus
- WinAPE emulator
- Arnold emulator
Common Causes
- Adding a string to a number (e.g. A$ + 5)
- Passing a string to a function that expects a number (e.g. SQR(A$))
- Assigning a string value to a numeric variable (e.g. A = "HELLO")
- Comparing a string with a number (e.g. IF A$ = 5)
- Using the wrong variable name — A and A$ are different variables
How to Fix It
-
Check the variable types in the offending line.
In Locomotive BASIC, variables ending in $ are strings (name$, a$). Variables ending in % are integers (count%). All other variables are floating-point numbers (x, score). Make sure you are not mixing these in expressions.
-
Use VAL() to convert a string to a number.
If a$ contains a number as text (like "42"), use VAL(a$) to get the numeric value. VAL("42") returns the number 42.
-
Use STR$() to convert a number to a string.
If you need to join a number into a string message: PRINT "Score: " + STR$(score)
-
Remember that A and A$ are completely different variables.
A is a number. A$ is a string. They can both exist at the same time with different values. Using the wrong one in an expression causes Type mismatch.
Frequently Asked Questions
Does the Amstrad CPC support integer variables?
Yes. Variables ending in % are integers (whole numbers). Using integers instead of floating-point numbers makes calculations faster on the CPC's Z80 processor.
Can I convert any string to a number with VAL()?
VAL() converts numeric strings like "42" or "3.14" to numbers. If the string does not start with a digit, VAL() returns 0. VAL("HELLO") returns 0, not an error.