This page has been archived, and is no longer updated.

Type Mismatch

QBASIC Type Mismatch dialog

Type mismatches often happen when something is being set equal to something else. For instance, take this code:

 foo$ = hello
 bar = "world"

Probably, the programmer was trying to make two variables, foo and bar, which have the words hello and world in them, respectively. However, both of these cause type mismatches.

Let's start with the first one. The variable, foo$, is a string variable, but hello is not. Because it is not enclosed in quotes, the computer thinks it is a numeric variable, and can't put a number where a word should go.

The second one has the same sort of problem. bar is a numeric variable (because it dosen't have a dollar sign after it), but "world" is a string, because it is in quotes. The computer can't put a word where a number should go, either. This code should be changed to say

 foo$ = "hello"
 bar$ = "world"

to make it work.

By the way, although QBASIC won't catch it, there can also be a type mismatch between what a programmer wanted to say and what a programmer said. Take this code segment:

 foo = hello
 PRINT foo

Running this causes QBASIC to output:

 0

What the code says to do is put the value of the (numeric) variable hello into the (again numeric) variable foo. Since hello hasn't been set to anything, it is 0, which means that foo is also 0. Probably, the code should say

 foo$ = "hello"
 PRINT foo$

Running this causes QBASIC to output:

 hello