Search code examples
type-mismatchqbasic

a = "stackoverflow" does not work in QBasic


The qbasic code returns a type mismatch error.

a="StackOverflow"
print left$(a,5)
print right$(a,8)

What is the cause of this error and how can I rectify it?


Solution

  • The error is caused by the way you have named the variable. "StackOverflow" is a string and cannot be assigned to variables of any other type.

    In Qbasic, string variables must end with a $ symbol. So try a$ instead of a.

    So try this code instead.

    a$="StackOverflow"
    print left$(a$,5)
    print right$(a$,8)